Class: ActiveRecord::Associations::Builder::HasOne
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
SingularAssociation ,
Association
|
|
Instance Chain:
self,
SingularAssociation ,
Association
|
|
Inherits: |
ActiveRecord::Associations::Builder::SingularAssociation
|
Defined in: | activerecord/lib/active_record/associations/builder/has_one.rb |
Constant Summary
Association
- Inherited
Class Attribute Summary
Association
- Inherited
Class Method Summary
- .touch_record(record, name, touch)
- .add_destroy_callbacks(model, reflection) private
- .add_touch_callbacks(model, reflection) private
- .define_callbacks(model, reflection) private
- .define_validations(model, reflection) private
- .macro private
- .valid_dependent_options private
- .valid_options(options) private
SingularAssociation
- Inherited
.define_accessors, | |
.define_constructors | Defines the (build|create)_association methods for belongs_to or has_one association. |
.valid_options |
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
.add_destroy_callbacks(model, reflection) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/has_one.rb', line 26
def self.add_destroy_callbacks(model, reflection) super unless reflection. [:through] end
.add_touch_callbacks(model, reflection) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/has_one.rb', line 46
def self.add_touch_callbacks(model, reflection) name = reflection.name touch = reflection. [:touch] callback = -> (record) { HasOne.touch_record(record, name, touch) } model.after_create callback, if: :saved_changes? model.after_create_commit { association(name).reset_negative_cache } model.after_update callback, if: :saved_changes? model.after_destroy callback model.after_touch callback end
.define_callbacks(model, reflection) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/has_one.rb', line 21
def self.define_callbacks(model, reflection) super add_touch_callbacks(model, reflection) if reflection. [:touch] end
.define_validations(model, reflection) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/has_one.rb', line 30
def self.define_validations(model, reflection) super if reflection. [:required] model.validates_presence_of reflection.name, message: :required end end
.macro (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/has_one.rb', line 5
def self.macro :has_one end
.touch_record(record, name, touch)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/has_one.rb', line 37
def self.touch_record(record, name, touch) instance = record.send(name) if instance&.persisted? touch != true ? instance.touch(touch) : instance.touch end end
.valid_dependent_options (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/has_one.rb', line 17
def self. [:destroy, :destroy_async, :delete, :nullify, :restrict_with_error, :restrict_with_exception] end
.valid_options(options) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/builder/has_one.rb', line 9
def self. ( ) valid = super + [:as, :through] valid += [:foreign_type] if [:as] valid += [:ensuring_owner_was] if [:dependent] == :destroy_async valid += [:source, :source_type, :disable_joins] if [:through] valid end