lib/mongoid/relations/referenced/many_to_many.rb in mongoid-3.1.7 vs lib/mongoid/relations/referenced/many_to_many.rb in mongoid-4.0.0.alpha1

- old
+ new

@@ -27,11 +27,11 @@ def <<(*args) docs = args.flatten return concat(docs) if docs.size > 1 if doc = docs.first append(doc) - base.add_to_set(foreign_key, doc.send(metadata.primary_key)) + base.add_to_set(foreign_key => doc.send(metadata.primary_key)) if child_persistable?(doc) doc.save end end unsynced(base, foreign_key) and self @@ -63,11 +63,11 @@ existing.push(doc.id) and unsynced(base, foreign_key) end end end if persistable? || _creating? - base.push_all(foreign_key, ids.keys) + base.push(foreign_key => ids.keys) end persist_delayed(docs, inserts) self end @@ -75,29 +75,23 @@ # relation without saving. # # @example Build a new document on the relation. # person.posts.build(:title => "A new post") # - # @overload build(attributes = {}, options = {}, type = nil) + # @overload build(attributes = {}, type = nil) # @param [ Hash ] attributes The attributes of the new document. - # @param [ Hash ] options The scoped assignment options. # @param [ Class ] type The optional subclass to build. # # @overload build(attributes = {}, type = nil) # @param [ Hash ] attributes The attributes of the new document. - # @param [ Hash ] options The scoped assignment options. # @param [ Class ] type The optional subclass to build. # # @return [ Document ] The new document. # # @since 2.0.0.beta.1 - def build(attributes = {}, options = {}, type = nil) - if options.is_a? Class - options, type = {}, options - end - - doc = Factory.build(type || klass, attributes, options) + def build(attributes = {}, type = nil) + doc = Factory.build(type || klass, attributes) base.send(foreign_key).push(doc.id) append(doc) doc.apply_post_processed_defaults unsynced(doc, inverse_foreign_key) yield(doc) if block_given? @@ -118,11 +112,11 @@ # # @since 2.1.0 def delete(document) doc = super if doc && persistable? - base.pull(foreign_key, doc.send(metadata.primary_key)) + base.pull(foreign_key => doc.send(metadata.primary_key)) target._unloaded = criteria unsynced(base, foreign_key) end doc end @@ -138,17 +132,14 @@ def nullify target.each do |doc| execute_callback :before_remove, doc end unless metadata.forced_nil_inverse? - criteria.pull(inverse_foreign_key, base.id) + criteria.pull(inverse_foreign_key => base.id) end if persistable? - base.set( - foreign_key, - base.send(foreign_key).clear - ) + base.set(foreign_key => base.send(foreign_key).clear) end after_remove_error = nil many_to_many = target.clear do |doc| unbind_one(doc) unless metadata.forced_nil_inverse? @@ -318,25 +309,11 @@ metadata.primary_key => { "$in" => object || [] } ), metadata ) end - # Get the criteria that is used to eager load a relation of this - # type. - # - # @example Get the eager load criteria. - # Proxy.eager_load(metadata, criteria) - # - # @param [ Metadata ] metadata The relation metadata. - # @param [ Array<Object> ] ids The ids of the documents to load. - # - # @return [ Criteria ] The criteria to eager load the relation. - # - # @since 2.2.0 - def eager_load(metadata, ids) - metadata.klass.any_in(_id: ids).each do |doc| - IdentityMap.set(doc) - end + def eager_load_klass + Relations::Eager::HasAndBelongsToMany end # Returns true if the relation is an embedded one. In this case # always false. #