Under mongoid and rails 3 I have a collection of Users and a collection a Projects which embed many Relationships, the models are:
class User
include Mongoid::Document
field :name, :type => String
referenced_in :relationship, :inverse_of => :user
endclass Project
include Mongoid::Document
field :title, :type => String
embeds_many :relationships
endclass Relationship
include Mongoid::Document
field :type, :type => String
references_one :user
embedded_in :subject, :inverse_of => :relationships
end
My problem is that the referenced user of a relationship is never saved into the relationship. For example for following command only saves :type:
project1 = Project.new( :title => "project1", :relationships => [ {:type => "master", :user => "4d779568bcd7ac0899000002"} ] )
My goal is to have a project document similar to this:
{ "_id" : ObjectId("4d77a8b2bcd7ac08da00000f"), "title" : "project1", "relationships" : [
{
"type" : "master",
"user" : ObjectId("4d775effbcd7ac05a8000002"),
"_id" : ObjectId("4d77a8b2bcd7ac08da000010")
}
] }
The :user is never present, am I missing something here? Thanks a lot for your help!
Ted
referenced_in :relationship
from user and changereferences_one :user
in relationship toreferenced_in :user
– rubish