sandre89
sandre89

Reputation: 5916

Rails Active Record - find record where the sum of two columns matches criteria

I have a Property model that has rooms and suites columns.

If I want to find all Properties that have rooms > 5, I can easily write:

Property.where("rooms > 5")

But I want to write a query that finds any Properties that have +5 rooms and suites, so it can be 6 rooms and 0 suites, 0 rooms and 6 suites, 3 rooms and 3 suites or any combination. What matters is that rooms + suites > 5.

How would I write such a query?

Upvotes: 2

Views: 110

Answers (1)

Uzbekjon
Uzbekjon

Reputation: 11823

Did you try?

Property.where("(rooms + suites) > 5")

Upvotes: 2

Related Questions