Forum: Ruby on Rails Find with polymorphic associations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sean S. (Guest)
on 2008-12-23 16:02
(Received via mailing list)
I have an Order model which has_many Shipments and has_many
Creditcards.  In my controller I'm trying to process various search
parameters so that I can search on a customer name.  I'd like to match
on the name in any of the shipments or creditcards.

I'm just not sure how to structure the conditions so that the Address
table is included since Address belongs_to addressable, :polymorphic
=> true.

TIA,

Sean
Sean S. (Guest)
on 2008-12-23 16:41
(Received via mailing list)
I made some progress with the following

Order.find(:all, :include => [{:shipments => :address}, {:creditcards
=> :address}], :conditions => ["lower(addresses.firstname) LIKE ?",
"%frank%])

This works but only for the shipping addresses. but it won't find the
creditcard address.  Any ideas?

TIA,

Sean
This topic is locked and can not be replied to.