class MongoModel::Associations::HasManyByIds::Association

Public Instance Methods

build(*args, &block) click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_ids.rb, line 60
def build(*args, &block)
  doc = scoped.new(*args, &block)
  new_documents << doc
  doc
end
create(*args, &block) click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_ids.rb, line 66
def create(*args, &block)
  scoped.create(*args, &block)
end
ensure_class(array) click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_ids.rb, line 74
def ensure_class(array)
  array.is_a?(Array) ? array.each { |i| super(i) } : super
end
find_target() click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_ids.rb, line 51
def find_target
  if ids.any?
    docs = Array.wrap(definition.scope.where(:id.in => (ids - new_document_ids))) + new_documents
    docs.sort_by { |doc| ids.index(doc.id) }
  else
    []
  end
end
ids() click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_ids.rb, line 40
def ids
  instance[property_name]
end
replace(array) click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_ids.rb, line 44
def replace(array)
  ensure_class(array)

  instance[property_name] = array.map { |i| i.id }
  super
end
scoped() click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_ids.rb, line 70
def scoped
  definition.scope.where(:id.in => ids)
end

Protected Instance Methods

new_document_ids() click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_ids.rb, line 83
def new_document_ids
  new_documents.map { |doc| doc.id }
end
new_documents() click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_ids.rb, line 79
def new_documents
  @new_documents ||= []
end
proxy_class() click to toggle source
# File lib/mongomodel/concerns/associations/has_many_by_ids.rb, line 87
def proxy_class
  Proxy
end