sql - Limit the amount of results in associated queries with Rails 3.2 -


i have following query:

@books = books.includes(:author, :pages)               .find(:all,                     :order => 'created_at desc') 

let's assume "pages" table has fields "words, pictures". blank pages, field "words" null. there many "pages" records per book.

the problem above query, retrieves pages each book. retrieve 1 page record example condition "not null" on "words" field. however, don't want exclude query results books not match pages query (i have 10 books in table , want 10 books retrieved. book.page association should "nil" books condition not match.)

i hope makes sense.

check question: rails 3 - eager loading conditions

it looks want

class category    has_many   :children,        :class_name => "category",                 :foreign_key => "parent_id"   has_many   :published_pages, :class_name => "page",                 :conditions  => { :is_published => true }  end 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -