Class: ActiveRecord::Associations::Builder::SingularAssociation
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/singular_association.rb |
Constant Summary
Association
- Inherited
Class Attribute Summary
Association
- Inherited
Class Method Summary
- .define_accessors(model, reflection) private
-
.define_constructors(mixin, name)
private
Defines the (build|create)_association methods for belongs_to or has_one association.
- .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_accessors(model, reflection) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/singular_association.rb', line 11
def self.define_accessors(model, reflection) super mixin = model.generated_association_methods name = reflection.name define_constructors(mixin, name) unless reflection.polymorphic? mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1 def reload_#{name} association(:#{name}).force_reload_reader end def reset_#{name} association(:#{name}).reset end CODE end
.define_constructors(mixin, name) (private)
Defines the (build|create)_association methods for belongs_to or has_one association
# File 'activerecord/lib/active_record/associations/builder/singular_association.rb', line 30
def self.define_constructors(mixin, name) 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(options) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/singular_association.rb', line 7
def self. ( ) super + [:required, :touch] end