class MongoModel::Associations::HasManyByForeignKey::Proxy
Constants
- OVERRIDE_METHODS
Pass these methods to the scope rather than the Array target
Public Instance Methods
<<(*documents)
click to toggle source
Calls superclass method
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 151 def <<(*documents) documents.flatten! ensure_class(documents) documents.each { |doc| association.assign(doc) } super if loaded? self end
[]=(index, doc)
click to toggle source
Calls superclass method
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 143 def []=(index, doc) ensure_class(doc) association.unset(target[index]) if target[index] association.assign(doc) super if loaded? self end
build(*args) { |doc| ... }
click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 122 def build(*args) association.build(*args) do |doc| self << doc yield doc if block_given? end end
create(*args) { |doc| ... }
click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 129 def create(*args) association.create(*args) do |doc| self << doc yield doc if block_given? end end
create!(*args) { |doc| ... }
click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 136 def create!(*args) association.create!(*args) do |doc| self << doc yield doc if block_given? end end
delete(doc)
click to toggle source
Calls superclass method
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 176 def delete(doc) association.unset(doc) super self end
delete_at(index)
click to toggle source
Calls superclass method
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 182 def delete_at(index) association.unset(target[index]) super self end
ids()
click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 188 def ids target.map { |doc| doc.id } end
insert(index, doc)
click to toggle source
Calls superclass method
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 162 def insert(index, doc) ensure_class(doc) association.assign(doc) super if loaded? self end
select(*args, &block)
click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 192 def select(*args, &block) if args.empty? target.select(&block) else association.scoped.send(:select, *args) end end
unshift(*documents)
click to toggle source
Calls superclass method
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 169 def unshift(*documents) ensure_class(documents) documents.each { |doc| association.assign(doc) } super if loaded? self end
Private Instance Methods
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
MongoModel::Associations::Base::Proxy#method_missing
# File lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb, line 201 def method_missing(method, *args, &block) if Array.method_defined?(method) && !OVERRIDE_METHODS.include?(method) target.send(method, *args, &block) elsif association.scoped.respond_to?(method) association.scoped.send(method, *args, &block) else super(method, *args, &block) end end