hyperrjas
hyperrjas

Reputation: 10744

verify that either attributes has a value defined and is different from "nil" with mongoid

I have a model Post with 2 attributes:

attr1 and attr2

I want check that either attributes have a value defined or are different from "nil".

How can I do it?

Thank you!

Upvotes: 0

Views: 64

Answers (1)

hyperrjas
hyperrjas

Reputation: 10744

The solution for this problem is the next query:

Post.any_of({ :attr1.ne => nil }, { :attr2.ne => nil})

Thank you very much!. Regards!

Upvotes: 1

Related Questions