spohlenz/mongomodel

Association a la ActiveRecord

Closed this issue · 2 comments

Hi,

I am going to like the MongoModel.
It is simpler and more straightforward than other mongo mappers.

Well, I have a question.

I wrote the following two classes:

class Group < MongoModel::Document
  property :name, String
  has_many :members
end

class Member < MongoModel::Document
  property :name, String
  belongs_to :group
end

Then I tested them:

g = Group.create(:name => 'X')
g.members << Member.new(:name => 'Alice')
g.members << Member.new(:name => 'Bob')

from_db = Group.find(g.id)
puts from_db.members.size

I expected '2' as the result by analogy with ActiveRecord.
But I got '0' instead.

Is this intentional?

Try using Member.create as well.

Or, try just a g.save after the associations are made.