Rick Denatale wrote:
> Then just change the joins to include:
> 
> Page.all(
>  :include => :book,
>  :conditions => ["books.library_id = ?", 1]
> )
> 
> Which will both allow you to refer to the books fields in the where
> clause, and return an collection of object graphs rather than page
> object corrupted with fields they shouldn't have.

That's true, but I lose control over :select

Page.all(
  :select => 'pages.id, pages.no',
  :include => :book,
  :conditions => ["books.library_id = ?", 1]
)

...will generate:

SELECT
  "pages"."id" AS t0_r0,
  "pages"."no" AS t0_r1,
  "pages"."book_id" AS t0_r2,
  "pages"."created_at" AS t0_r3,
  "pages"."updated_at" AS t0_r4,
  "books"."id" AS t1_r0,
  "books"."title" AS t1_r1,
  "books"."year" AS t1_r2,
  "books"."library_id" AS t1_r3,
  "books"."created_at" AS t1_r4,
  "books"."updated_at" AS t1_r5
FROM
  "pages"
  LEFT OUTER JOIN "books" ON "books".id = "pages".book_id
WHERE
  (books.library_id = 1)

The real "books" and "pages" have decimal and large text columns that 
are not always needed.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to