Reputation: 527
I have two models called Post and User, Post belongs_to user and User has_many posts. When I list all posts I also want the user username and email to be included. I a relational database I would use join but how can I do this with Mongoid?
Upvotes: 0
Views: 170
Reputation: 9659
What you'll want to do is eager load your User
model when querying for your posts. You can do this using the includes
method.
Using your example above, you could do something like:
Post.includes(:user).all
Upvotes: 0