As a mongodb veteran, I created the following structure:
User: {
name: str,
email: ...
}
Gift: {
author: object_id(...),
receiver: object_id(...),
name: str
...
}
And I would like to map this to mongoid correctly:
class User
include Mongoid::Document
has_many :gifts
end
class Gift
include Mongoid::Document
belongs_to :user
end
However, the display is incorrect. g = Gift.first; g.author is undefined. How do I make a link?
Technically, this is:
User <--- 1: N via author---> Gift <--- N:1 via receiver---> User
(this means that the user can be the author of many gifts, and the user can be the recipient of many gifts, BUT a gift can only have 1 author and recipient).
Help Plz !!!
source
share