Reputation: 2829
I have a user model with attributes firstname
and lastname
. Instead of looking up users by id, is there a way I can look them up by firstname lastname pairs? There can be duplicate first names and duplicate last names; however, I don't allow for there to be duplicate firstname-lastname pairs.
Thanks.
Upvotes: 0
Views: 57
Reputation: 1811
If you're using Rails 4: User.find_by(firstname: "Joe", lastname: "Smith")
Otherwise: User.where(firstname: "Joe", lastname: "Smith").first()
Upvotes: 4