Class: ActiveRecord::Associations::Builder::SingularAssociation
- Inherits:
-
Association
- Object
- Association
- ActiveRecord::Associations::Builder::SingularAssociation
- Defined in:
- activerecord/lib/active_record/associations/builder/singular_association.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from Association
#model, #name, #options, #scope
Instance Method Summary collapse
- #constructable? ⇒ Boolean
- #define_accessors ⇒ Object
-
#define_constructors ⇒ Object
Defines the (build|create)_association methods for belongs_to or has_one association.
- #valid_options ⇒ Object
Methods inherited from Association
build, #build, #configure_dependency, #define_readers, #define_writers, #initialize, #macro, #mixin, #valid_dependent_options, #validate_options
Constructor Details
This class inherits a constructor from ActiveRecord::Associations::Builder::Association
Instance Method Details
#constructable? ⇒ Boolean
9 10 11 |
# File 'activerecord/lib/active_record/associations/builder/singular_association.rb', line 9 def constructable? true end |
#define_accessors ⇒ Object
13 14 15 16 |
# File 'activerecord/lib/active_record/associations/builder/singular_association.rb', line 13 def define_accessors super define_constructors if constructable? end |
#define_constructors ⇒ Object
Defines the (build|create)_association methods for belongs_to or has_one association
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'activerecord/lib/active_record/associations/builder/singular_association.rb', line 20 def define_constructors mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def build_#{name}(*args, &block) association(:#{name}).build(*args, &block) end def create_#{name}(*args, &block) association(:#{name}).create(*args, &block) end def create_#{name}!(*args, &block) association(:#{name}).create!(*args, &block) end CODE end |
#valid_options ⇒ Object
5 6 7 |
# File 'activerecord/lib/active_record/associations/builder/singular_association.rb', line 5 def super + [:remote, :dependent, :counter_cache, :primary_key, :inverse_of] end |