如何获取杂种中的所有embeds_many项目
我正在使用牛角,我有两个模型:
class User
include Mongoid::Document
include Mongoid::Timestamps
embeds_many :tickets
field :email, type: String
end
class Ticket
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :user
field :body, type: String
end
如何从ticket
为任何用户获取所有记录? 当我使用ticket.all
时,我得到nil
。
I'm Using Mongoid and I have two models:
class User
include Mongoid::Document
include Mongoid::Timestamps
embeds_many :tickets
field :email, type: String
end
class Ticket
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :user
field :body, type: String
end
How can I do get all records from Ticket
for any users?
When I use Ticket.all
, I get nil
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不好,但是工作的答案
正在工作,但是它会向您提出n请求数据库(n =用户数),不知道是否还有另一种使用mongoid进行此操作的方法。
Bad but working answer
It's working but it gonna make N request to you database (N=number of user), don't know if there is another way of doing this with mongoid.