1

I have a Trees Class in my rails application. In there I have a field called 'leaves'. Now for a certain operation, I need to execute the following SQL command with a bitwise & operation under condition.

SELECT * FROM trees WHERE (leaves & 6) = 6

How do I do it using datamapper ? I do not want to do it in the below way :

repository(:default).adapter.select('SELECT * FROM trees WHERE (leaves & 6) = 6')
sid_09
  • 461
  • 4
  • 18

1 Answers1

1

You can use :conditions.

Tree.all(:conditions => ['(leaves & ?) = ?', 6, 6])
ujifgc
  • 2,215
  • 2
  • 19
  • 21