Hello!
I am developing a small application in Rails 3. In this application users can be connected to each other. I am mainly using two tables to store user data and relations. I want to search these tables with either firstname or lastname to get the contacts of a user.
Table ONE - Profiles
In this table I am storing Firstname, Lastname and Id of a user.
Table TWO - Contacts
In this table I am storing the ID (profile_id) of the user and the ID of the user he is connected to (friend_id).
I am using the following query, but it does not get the correct results.
Profile.find_by_sql("SELECT * FROM contacts
INNER JOIN profiles ON contacts.friend_id = profiles.id WHERE profiles.firstname = '#{@keyword}' OR profiles.lastname = '#{@keyword}'")
What is wrong with is and how can it be more effective?
Thankful for all help!