Created
July 9, 2010 19:45
-
-
Save jacquescrocker/469948 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
end | |
class Post | |
include Mongoid::Document | |
references_many :comments | |
end | |
class Comment | |
include Mongoid::Document | |
field :user_id | |
referenced_in :parent, :inverse_of => :comment | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I have several users, several posts and for every post, several comments. | |
Every post has one user. However the user table isn't on mongodb (I could talk with you about why. But please, that's not the question here). | |
I'm looking forward getting all the comments for one user. | |
So looping through all the posts to get the comments with user_id = x. |
Yeah. But I'd loose all the advantages there is with embedded documents.
dmathieu: yep, I agree. I think shingara's query is better
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
now you can do
Comment.where(:user_id => params[:user_id])
to return the results