Find for multiple tables & updates

Would like to use ActiveRecord find for multiple table lookups with sort
order on parent table.

Example: Item table belongs to Category and Section tables. Category and
Section tables have only 2 attributes: id, text field (category and
section). Item has many attributes in addition to category_id &
section_id.

1. Sort items by category or section TEXT field not the id fields.
2. Be able to update the Item attributes but not category or

section.

A. Use find_by_sql?
B. Use find and “:include” option.
C. Use “:from” option to refer to an SQL view of the joined tables?
i. Then switch to an updatable Item form?
D. Use some other approach?

Best regards,

Ken W.
Sugar Creek, Missouri
The “Show Me” state.

Go with B.

Items.find(:all, :include=>[:category, :section],
:order=>“categories.name,
sections.name, items.name”)

The key is the :order option.

On Feb 19, 8:45 pm, Ken W. [email protected]

AndyV wrote:

Go with B.

Items.find(:all, :include=>[:category, :section],
:order=>“categories.name,
sections.name, items.name”)

The key is the :order option.

On Feb 19, 8:45 pm, Ken W. [email protected]

Works like a charm! A little tweaking and the rails magic delights once
again.

Rails is extraordinarily amazing. (Once you know how it works. :slight_smile:

If only the documentation and examples were a bit more illuminating.
Sigh.

Many thanks, Andy.

Ken W. wrote:

AndyV wrote:

If only the documentation and examples were a bit more illuminating.
Sigh.

Many thanks, Andy.

Offtopic but I /sign this “petition”.

:slight_smile: