Class: ActiveRecord::Associations::Builder::CollectionAssociation
Do not use. This class is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Association
|
|
Instance Chain:
self,
Association
|
|
Inherits: |
ActiveRecord::Associations::Builder::Association
|
Defined in: | activerecord/lib/active_record/associations/builder/collection_association.rb |
Constant Summary
-
CALLBACKS =
# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 7[:before_add, :after_add, :before_remove, :after_remove]
Association
- Inherited
Class Attribute Summary
Association
- Inherited
Class Method Summary
- .define_callbacks(model, reflection)
- .define_callback(model, callback_name, name, options) private
- .define_extensions(model, name, &block) private
-
.define_readers(mixin, name)
private
Defines the setter and getter methods for the collection_singular_ids.
- .define_writers(mixin, name) private
- .valid_options(options) private
Association
- Inherited
.build, .create_reflection, .add_after_commit_jobs_callback, .add_destroy_callbacks, .build_scope, .check_dependent_options, | |
.define_accessors | Defines the setter and getter methods for the association class Post < |
.define_callbacks, .define_change_tracking_methods, .define_extensions, .define_readers, .define_validations, .define_writers, .macro, .valid_dependent_options, .valid_options, .validate_options |
Class Method Details
.define_callback(model, callback_name, name, options) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 30
def self.define_callback(model, callback_name, name, ) full_callback_name = "#{callback_name}_for_#{name}" callback_values = Array( [callback_name.to_sym]) method_defined = model.respond_to?(full_callback_name) # If there are no callbacks, we must also check if a superclass had # previously defined this association return if callback_values.empty? && !method_defined unless method_defined model.class_attribute(full_callback_name, instance_accessor: false, instance_predicate: false) end callbacks = callback_values.map do |callback| case callback when Symbol ->(method, owner, record) { owner.send(callback, record) } when Proc ->(method, owner, record) { callback.call(owner, record) } else ->(method, owner, record) { callback.send(method, owner, record) } end end model.send "#{full_callback_name}=", callbacks end
.define_callbacks(model, reflection)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 13
def self.define_callbacks(model, reflection) super name = reflection.name = reflection. CALLBACKS.each { |callback_name| define_callback(model, callback_name, name, ) } end
.define_extensions(model, name, &block) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 22
def self.define_extensions(model, name, &block) if block_given? extension_module_name = "#{name.to_s.camelize}AssociationExtension" extension = Module.new(&block) model.const_set(extension_module_name, extension) end end
.define_readers(mixin, name) (private)
Defines the setter and getter methods for the collection_singular_ids.
# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 58
def self.define_readers(mixin, name) super mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name.to_s.singularize}_ids association(:#{name}).ids_reader end CODE end
.define_writers(mixin, name) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 68
def self.define_writers(mixin, name) super mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def #{name.to_s.singularize}_ids=(ids) association(:#{name}).ids_writer(ids) end CODE end
.valid_options(options) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/collection_association.rb', line 9
def self. ( ) super + [:before_add, :after_add, :before_remove, :after_remove, :extend] end