我有两个模型。
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