views:

72

answers:

1

example: Person has_many Comments. Comments has named_scope :approved. And I need to serialize Person with all approved comments to JSON. So it should look like this:

person.to_json(:include => :comments)

but how can I add there that named scope? To serialize just that approved ones?

A: 

I dont know if this is supported, but eventually you add your named scopes conditions here in the query. Not the best solution but works.

person.to_json(:include => :comments, :conditions=>['comments.approved = ?', true])

Hope this helps.

dombesz