Reputation: 2693
I'm attempting to write a script to query a database for a combination of values using ruby on rails. My aim is to find out the following: Where column1==x
, does column2==y
?
I had thought the following would do the trick but it seems not to.
MyValues.where(column1: x, column2: y)
Rather, it kicks out something like the following:
IdKey::ActiveRecord_Relation:0x00000004ae4d28
Any ideas where I might be going wrong and how I might go right?
As always, the help is much appreciated.
Upvotes: 0
Views: 252
Reputation: 434685
If you're only interested in existence then say so:
MyValues.where(column1: x, column2: y).exists?
# or
MyValues.exists?(column1: x, column2: y)
If you just say MyValues.where(column1: x, column2: y)
then you're going to get a relation back so that you can add more conditions, ordering, etc. and a relation won't touch the database until you do something that requires it to.
Upvotes: 1