Yogi wrote:
> Three simple models setup with :through association
>
>
> Person
> has_many :readings
> has_many :books, :through => :readings
>
>
> Reading
> belongs_to :person
> belongs_to :book
>
>
> Book
> has_many :readings
> has_many :persons, :through => :readings
>
>
> I want to search persons names and all his books names and return
> matching persons. how do i correctly form a search like this
> syntatically wrong one
>
> Person.find(:all, :conditions => ["person.name LIKE ? and book.name
> LIKE ?", "%#{params[:person_name]}%", "%#{params[:book_name]}%"])
That looks syntactically correct. It just needs a little tweaking:
Person.find(:all, :select => 'DISTINCT people.*', :joins => :books,
:conditions => ["people.name LIKE ? AND books.name LIKE ?",
"%#{params[:person_name]}%", "%#{params[:book_name]}%"]
--
Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.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
-~----------~----~----~----~------~----~------~--~---