I want to find records based on more than parameters. But those parameters are of mupltiple options.
As "SELECT something FROM mytable WHERE user_name="xyz" and status=("Active" OR "Deleted")
How do I translate this to rails statement?
Person.find_by_user_name_and_status(user_name, status) # this doesn't take the OR operator
I can't test it right now, but did you try this?
Person.find_all_by_user_name_and_status(user_name, ["active", "deleted"])
if the above does not work, this should...
Person.where(:user_name => "xyz", :status => ["active", "deleted"])
# translates to:
# "select * from persons where username = 'xyz' and status in ('active', 'deleted')"
You should take a look into the Rails Guide for Active Record: http://guides.rubyonrails.org/active_record_querying.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With