Datamapper (ruby) - (Using the sample blog) Receive posts that have no comments

First SO question after using this place for reference on many other things .. I'm nervous.

DataMapper .. Using a Blog model for example (posts, comments, etc. - http://datamapper.org/docs/associations.html ) I'm trying to train how to get blog posts that have no comments ..

So something like Post.all (: comments => {: comment => nil})

Lot has a lot of luck: (

I read here that for complex reporting queries it is best to flush SQL, but of course the way to do this is not so. SO?

Thanks in advance.

+3
source share
1 answer

Post (, "comments_count" ), . :

Post.find(:all, :include => :comments).select { |post| post.comments.empty? }

( ):

Post.all(:conditions => { :comments_count => 0 })

, Rails 3 ( ).

+3

Source: https://habr.com/ru/post/1732255/


All Articles