I’m working to create the following ruby on rails 3 query:
User.rb
search_results = self.find( :all,
:select => 'id,fb_id,fname,lname,org_id',
:conditions => ["guest = ? AND fb_id != ? AND trim(lower(fname)) || ' ' || trim(lower(lname)) LIKE ?", false, nil, '%'+"#{q.downcase}"+'%'],
:limit => 8
)
Conditions being:
- User needs to be either guest == false or have a fb_id that’s not null
- If 1 is true, then find based on the user.fname and user.lname
This is returning nothing. I’m guessing I’m messing up with #1. Any suggestions on what’s wrong with the condition or a better way to handle this query? Thanks
check the log to see exactly what the query to the database is. Ensure that there really are the records in the db that you think there are.
If the request is
User needs to be either guest == false or have a fb_id that's not nullthen the query should beEdited I left out the not in the null test. I also improved the setting of q2. I followed mu’s suggestion on handling dbms-specific false constants.