【发布时间】:2013-07-18 18:27:53
【问题描述】:
我有两个模型。
class User
include Mongoid::Document
field :name, type: String
embeds_many :posts
end
class Post
include Mongoid::Document
field :comment, type: String
embedded_in :user
end
现在假设我得到了第一个用户的第一个帖子,然后我调用了用户的名字。这会导致调用额外的查询,还是父文档是帖子的一部分?
posts = User.first.posts
first_post = posts.first
# Will this line of code below initiate a query search for users?
users_name = first_post.user.name
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 mongodb mongoid associations