Class: ActiveRecord::Associations::Builder::Association
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::Builder::Association
- Defined in:
- lib/active_record/associations/builder/association.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary collapse
- VALID_OPTIONS =
:nodoc:
[:class_name, :anonymous_class, :foreign_key, :validate]
Class Attribute Summary collapse
-
.extensions ⇒ Object
Returns the value of attribute extensions.
Class Method Summary collapse
- .build(model, name, scope, options, &block) ⇒ Object
- .create_reflection(model, name, scope, options, &block) ⇒ Object
Class Attribute Details
.extensions ⇒ Object
Returns the value of attribute extensions.
17 18 19 |
# File 'lib/active_record/associations/builder/association.rb', line 17 def extensions @extensions end |
Class Method Details
.build(model, name, scope, options, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/active_record/associations/builder/association.rb', line 23 def self.build(model, name, scope, , &block) if model.dangerous_attribute_method?(name) raise ArgumentError, "You tried to define an association named #{name} on the model #{model.name}, but " \ "this will conflict with a method #{name} already defined by Active Record. " \ "Please choose a different association name." end reflection = create_reflection(model, name, scope, , &block) define_accessors model, reflection define_callbacks model, reflection define_validations model, reflection reflection end |
.create_reflection(model, name, scope, options, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/active_record/associations/builder/association.rb', line 37 def self.create_reflection(model, name, scope, , &block) raise ArgumentError, "association names must be a Symbol" unless name.kind_of?(Symbol) () extension = define_extensions(model, name, &block) [:extend] = [*[:extend], extension] if extension scope = build_scope(scope) ActiveRecord::Reflection.create(macro, name, scope, , model) end |