Using the NOT operator with Squeel?
2 answers
It is very important to note that ActiveRecord stores boolean values as string flags in the database. Therefore, in the mentioned case, document.deleted
equals 'f'
, which is the true value. Therefore, you cannot just use the operator NOT
.
Perhaps what you are looking for:
Document.where { deleted.eq(false) | deleted.eq(nil) }
Greetings
+2
source to share
NOT
will change the returned set, so you have to define what you are comparing.
(-deleted) #there is nothing to reverse
Based on your comment I think you mean deleted not equal true
, therefore:
Document.where { -(deleted == true) | (deleted == nil) }
However, the opposite of true is false, right? So you can say:
Document.where { (deleted == false) | (deleted == nil) }
+2
source to share