Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

association_reflections

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

association_reflections

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Association Reflections (Rails)

This gem lets you access form parameters in your model.


Why would you want that?

  • See associations marked for deletion
  • See all form parameters

Installation

gem 'association_reflections'

Full example

class User < ApplicationRecord
  include AssociationReflections::Concern
  
  has_many :projects
  
  accepts_nested_attributes_for :projects, allow_destroy: true
  
  validate :validate_associations
  
  private
  
  def validate_associations
  
    reflection = self.association_reflections
    # => <AssociationReflections::Association>
  
    reflection.params
    # {
    #   "email"               => "",
    #   "projects_attributes" => {
    #     "0" => {
    #       "id"                    => "1",
    #       "name"                  => "",
    #       "_destroy"              => "1",
    #       "categories_attributes" => {
    #         "0" => {
    #           "name" => ""
    #         }
    #       }
    #     }
    #   }
    # }
    
  end
end
class Project < ApplicationRecord
  belongs_to :user
  has_many   :categories
  
  accepts_nested_attributes_for :categories, allow_destroy: true
  
  validate :validate_associations
  
  private
  
  def validate_associations
    reflection = self.user.association_reflections
  end
  
end
class Category < ApplicationRecord
  belongs_to :project
  
  validate :validate_associations
  
  private
  
  def validate_associations
    reflection = self.project.user.association_reflections
  end
  
end

Note

It must be noted that this only works when using update and create methods.

FAQs

Package last updated on 10 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc