catalogues.name
catalogue_items.position
products.name
products. price
WHERE
catalogues.name LIKE "xxx%"
First of all, amend your association in Catalogue as follows - this will
mean that the catalogue's items (and therefore products) will
automatically be ordered by position.
#do an include to eager load the relevant associations.
@catalogues = Catalogue.find(:all, :conditions => ["name like ?",
"#{a_variable}%"], :include => {:catalogue_items => :products})
And then, for example, in the view:
<% @catalogues.each do |catalogue| %>
<div>Catalogue:<%= catalogue.name %></br/>
<% catalogue.catalogue_items.each do |item| %>
<div class="product"><%= item.position %>: <%= item.product.name
%>: <%= item.product.price %></div>
<% end %>
</div>
<% end %>
Obviously you can put your own html around this, this is just a simple
example.
That doesn't make sense though - you're trying to shove a search
condition into the order option, and you've got all sorts of syntax
errors going on.
Can you explain, in english as opposed to code, what it is that you
ultimately want to do? Neither of the things you've asked for have
really made sense so i'm just guessing. You're asking how to do a
particular bit of code but i don't think the code you're looking for is
actually the code you need to do the job, if you know what i mean.
That's not any clearer - you're still just giving code examples. Like,
with the two examples there, you don't say if either of them gives the
results you want, and if they don't why not.