Class: DataMapper::Associations::RelationshipChain
- Object
- DataMapper::Associations::Relationship
- DataMapper::Associations::RelationshipChain
Constants
- OPTIONS
- [ :repository_name, :near_relationship_name, :remote_relationship_name, :child_model_name, :parent_model_name, :parent_key, :child_key, :min, :max ]
Constructor Summary
private
initialize(options)
[View source]
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
# File 'dm-core/lib/dm-core/associations/relationship_chain.rb', line 58 def initialize(options) if (missing_options = options.keys - OPTIONS).any? raise ArgumentError, "The options #{missing_options * ', '} are required" end @repository_name = options.fetch(:repository_name) @near_relationship_name = options.fetch(:near_relationship_name) @remote_relationship_name = options.fetch(:remote_relationship_name) @child_model_name = options.fetch(:child_model_name) @parent_model_name = options.fetch(:parent_model_name) @parent_properties = options.fetch(:parent_key) @child_properties = options.fetch(:child_key) @name = near_relationship.name @query = options.reject{ |key,val| OPTIONS.include?(key) } @extra_links = [] @options = options end
Public Visibility
Public Instance Method Summary
| #child_model | |
|---|---|
| #get_children(parent, options = {}, finder = :all) |
Public Instance Methods Inherited from DataMapper::Associations::Relationship
attach_parent, child_key, get_parent, parent_key, parent_model
Public Instance Methods Inherited from Object
Public Instance Method Details
child_model
public
child_model
[View source]
23 24 25 26 27 28
# File 'dm-core/lib/dm-core/associations/relationship_chain.rb', line 23 def child_model near_relationship.child_model end
get_children
public
get_children(parent, options = {}, finder = :all)
[View source]
13 14 15 16 17 18 19 20 21
# File 'dm-core/lib/dm-core/associations/relationship_chain.rb', line 13 def get_children(parent, options = {}, finder = :all) query = @query.merge(options).merge(child_key.to_query(parent_key.get(parent))) query[:links] = links DataMapper.repository(parent.repository.name) do finder == :first ? grandchild_model.first(query) : grandchild_model.all(query).uniq end end