Class: Mongoid::Association::Referenced::HasOneThrough
- Inherits:
-
Object
- Object
- Mongoid::Association::Referenced::HasOneThrough
- Includes:
- Mongoid::Association::Relatable
- Defined in:
- lib/mongoid/association/referenced/has_one_through.rb,
lib/mongoid/association/referenced/has_one_through/eager.rb,
lib/mongoid/association/referenced/has_one_through/proxy.rb
Overview
Metadata class for has_one :through associations.
Defined Under Namespace
Constant Summary collapse
- ASSOCIATION_OPTIONS =
The options available for this type of association, in addition to the common ones.
i[source through].freeze
- VALID_OPTIONS =
The complete list of valid options for this association, including the shared ones.
(ASSOCIATION_OPTIONS + SHARED_OPTIONS).freeze
Constants included from Mongoid::Association::Relatable
Mongoid::Association::Relatable::PRIMARY_KEY_DEFAULT, Mongoid::Association::Relatable::SHARED_OPTIONS
Instance Attribute Summary
Attributes included from Mongoid::Association::Relatable
#name, #options, #owner_class, #parent_inclusions
Instance Method Summary collapse
-
#criteria(base) ⇒ Document | nil
Resolve the target by delegating through the intermediate proxy.
-
#embedded? ⇒ false
Is this association embedded?.
-
#relation ⇒ Class
The proxy class for this association type.
-
#relation_complements ⇒ Array
The list of association complements.
-
#setup! ⇒ self
Setup instance methods on the owner class.
-
#source_association ⇒ Mongoid::Association::Relatable
The source association metadata on the intermediate class.
-
#stores_foreign_key? ⇒ false
Through associations never store a foreign key on the owner document.
-
#through_association ⇒ Mongoid::Association::Relatable
The intermediate association metadata on the owner class.
-
#validation_default ⇒ false
The default for validating the association object.
Methods included from Mongoid::Association::Relatable
#==, #bindable?, #counter_cache_column_name, #create_relation, #destructive?, #extension, #foreign_key_check, #foreign_key_setter, #get_callbacks, #in_to?, #initialize, #inverse, #inverse_association, #inverse_class, #inverse_class_name, #inverse_setter, #inverse_type, #inverse_type_setter, #inverses, #key, #many?, #many_to_many?, #one?, #path, #relation_class, #relation_class_name, #setter, #try_relation_class, #type_setter, #validate?
Methods included from Options
#as, #autobuilding?, #autosave, #cascading_callbacks?, #counter_cached?, #cyclic?, #dependent, #fallback, #fallback?, #forced_nil_inverse?, #indexed?, #inverse_of, #order, #polymorphic?, #primary_key, #store_as, #touch_field, #touchable?, #type
Methods included from Constrainable
Instance Method Details
#criteria(base) ⇒ Document | nil
Resolve the target by delegating through the intermediate proxy. Unlike other association types, this returns a document (or nil) directly rather than a Mongoid::Criteria, because the two-hop traversal is performed eagerly via the existing association proxy.
118 119 120 121 122 123 |
# File 'lib/mongoid/association/referenced/has_one_through.rb', line 118 def criteria(base) through_target = base.public_send(through_association.name) return nil if through_target.nil? through_target.public_send(source_association.name) end |
#embedded? ⇒ false
Is this association embedded?
43 44 45 |
# File 'lib/mongoid/association/referenced/has_one_through.rb', line 43 def false end |
#relation ⇒ Class
The proxy class for this association type.
50 51 52 |
# File 'lib/mongoid/association/referenced/has_one_through.rb', line 50 def relation Proxy end |
#relation_complements ⇒ Array
The list of association complements.
28 29 30 |
# File 'lib/mongoid/association/referenced/has_one_through.rb', line 28 def relation_complements [].freeze end |
#setup! ⇒ self
Setup instance methods on the owner class.
35 36 37 38 |
# File 'lib/mongoid/association/referenced/has_one_through.rb', line 35 def setup! setup_instance_methods! self end |
#source_association ⇒ Mongoid::Association::Relatable
The source association metadata on the intermediate class. Resolved lazily to allow forward references.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/mongoid/association/referenced/has_one_through.rb', line 82 def source_association @source_association ||= begin source_name = ([:source] || name).to_s assoc = through_association.klass.relations[source_name] || raise( Errors::InvalidRelationOption.new( @owner_class, name, :source, source_name ) ) if assoc.is_a?(Referenced::HasAndBelongsToMany) raise( Errors::InvalidRelationOption.new( @owner_class, name, :source, 'has_and_belongs_to_many is not supported as a :through source' ) ) end assoc end end |
#stores_foreign_key? ⇒ false
Through associations never store a foreign key on the owner document.
106 107 108 |
# File 'lib/mongoid/association/referenced/has_one_through.rb', line 106 def stores_foreign_key? false end |
#through_association ⇒ Mongoid::Association::Relatable
The intermediate association metadata on the owner class. Resolved lazily to allow forward references.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mongoid/association/referenced/has_one_through.rb', line 58 def through_association @through_association ||= begin assoc = @owner_class.relations[[:through].to_s] || raise( Errors::InvalidRelationOption.new( @owner_class, name, :through, [:through] ) ) if assoc. raise( Errors::InvalidRelationOption.new( @owner_class, name, :through, 'through association must be a referenced association, not embedded' ) ) end assoc end end |
#validation_default ⇒ false
The default for validating the association object.
128 129 130 |
# File 'lib/mongoid/association/referenced/has_one_through.rb', line 128 def validation_default false end |