Mongoid::错误::混合关系:Mongoid +设计
我有一个来自 Devise 的模型用户,具有这种关系:
user.rb
# Relationships
references_many :houses, :dependent => :delete
现在我有一个用脚手架创建的模型屋:
house.rb
# Relationships
referenced_in :user, :inverse_of => :houses
embeds_many :deals
现在我有一个模型处理这种关系:
embedded_in :house, :inverse_of => :deals
在我的 paths.rb 中,我有:
resources :houses do
resources :deals
end
当我尝试获取在控制台中进行交易的用户:
ruby-1.9.2-p180 :009 > User.first.deals.first
我收到下一个错误:
Mongoid::Errors::MixedRelations: Referencing a(n) Deal document from the User document via a relational association is not allowed since the Deal is embedded.
I have a Model User from Devise with that relations:
user.rb
# Relationships
references_many :houses, :dependent => :delete
Now I have a Model House created with scaffold:
house.rb
# Relationships
referenced_in :user, :inverse_of => :houses
embeds_many :deals
Now I have a Model Deal with this relations:
embedded_in :house, :inverse_of => :deals
In my routes.rb I have:
resources :houses do
resources :deals
end
When I try get the user that make the deal in console:
ruby-1.9.2-p180 :009 > User.first.deals.first
I get the next error:
Mongoid::Errors::MixedRelations: Referencing a(n) Deal document from the User document via a relational association is not allowed since the Deal is embedded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您提供的信息,用户与交易没有直接关系。
您似乎试图这样做:
由于您的交易嵌入到房屋中,因此您无法通过关系直接从用户访问它们。
这是 Mongoid 的一个已知限制。
您可以使用:
With the information you provided, an user is not directly related to a deal.
It seems that you tried to do :
As your Deals are embedded into Houses, you can't access them directly from Users through a relation.
It is a known limitation of Mongoid.
You can use :