Skip to content

Commit

Permalink
Updating rdoc on has_many_related
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Dec 13, 2009
1 parent 83e7618 commit c8f6b18
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/mongoid/associations/has_many_related.rb
Expand Up @@ -5,14 +5,23 @@ class HasManyRelated < DelegateClass(Array) #:nodoc:

attr_reader :klass

# Instantiate a new associated object and add it to the relationship.
# Builds a new Document and adds it to the association collection. The
# document created will be of the same class as the others in the
# association, and the attributes will be passed into the constructor.
#
# Returns the newly created object.
def build(attributes)
object = @klass.instantiate(attributes.merge(@foreign_key => @parent.id))
@documents << object
object
end

# Create a new object for the association, save it, and add it.
# Creates a new Document and adds it to the association collection. The
# document created will be of the same class as the others in the
# association, and the attributes will be passed into the constructor and
# the new object will then be saved.
#
# Returns the newly created object.
def create(attributes)
object = build(attributes)
object.save
Expand Down

0 comments on commit c8f6b18

Please sign in to comment.