Hi, I have these models:
class Comment < ActiveRecord::Base
belongs_to :post
belongs_to :user
end
class Post < ActiveRecord::Base
has_many :comments
belongs_to :user
end
class User < ActiveRecord::Base
has_many :posts
has_many :comments
end
I'm trying to pull out Post data, while eager loading the User and Comment data as well, but with the limitation of not loading the Comments which have been blocked (TINYINT field in the Comment table). The following works when there are comments present, but it's causing issues when I load posts that don't have any comments yet:
@post = Post.find(params[:id],
:include => {:comments => :user},
:conditions => "comments.blocked = 0")
Any suggestions on how I can run this query such that it will work when no comments are present? Thanks.