I am working on writing a search method where a user can type a string
of words and I return all the objects that have fields that match all of
the words in one or a combination of fields.
Person has_many :pets
I want to write some SQL so that if I search for “Tony AAAA” I will get
all the people who have Tony and AAA either in their first_name or
last_name fields or in any of their pet’s name fields. For example, it
would be ok to return a person if their first_name is Tony and they have
a pet named AAAA. It would also be ok to return a person if their first
name was Tony and last name was AAAA.
I need for this to work for an arbitrary number of words in the search
string so I assume that I will have to do some ruby string manipulation
to modify the query.
Any advice on how to start? I don’t know much SQL right now but I think
a join would be used here as I need info from both the people table and