> > So now let''s say I get a tag object, and I want to find all
the items
> > in it that are available.
> > tag.items.find(:all, :conditions => "available is true")
> >
> > That''s the intuitive, rails-like way to do it. But the
generated SQL
> > is "select * from items where tag_id=1 and available is
true" Which
> > obviously doesn''t work because an item doesn''t have
a tag_id. So how
> > can I use find() to do what I want?
Try this:
tag.items.find(:all, :conditions => ''items.available is
true'', :joins
=> ''INNER JOIN items_tags ON tags.id = items_tags.tag_id INNER JOIN
items ON items.id = items_tags.item_id'')
Otherwise, I''d define a habtm assocation like
has_and_belongs_to_many :available_items, :class_name =>
''Item'',
:conditions => ''available is true''
--
rick
http://techno-weenie.net