Topic: how can i write this? post belongs to user

hi,
i am trying to do grab all the latest posts of a community where post belongs to a user.r but the user must have their account activated which is a field in the user table?


BlogPost.find(:all, :conditions => ["is_private = ? and user_id.activated = true", 0], :order => "created_at DESC", :limit => 5)

thanks for the help!

Last edited by bbqplate (2008-05-31 11:36:06)

Re: how can i write this? post belongs to user

Try:

BlogPost.find(:all, :include => [:user], :conditions => ["blogposts.is_private = ? AND users.activated =?", 0, true], :order => "blogposts.created_at DESC", :limit => 5)

ThinkRefresh - Free Rails Techniques Screencasts