Reputation: 1435
I have a model Account that has_and_belongs_to_many :categories
.
When testing whether a given category is already linked to an account (before creating it), I do this:
account = Account.find(1)
account.categories.where(name: "rent").none?
This returns false
(although "rent" is a categorie for an account that already exists).
account.categories.where(name: "monkey").none?
returns true
Why doesn't an existing relation return true
and an non existing false
? Or should I use another method for testing this?
Upvotes: 0
Views: 149
Reputation: 14890
You probably want the any?
method since...
[1,2].none?
=> false
[1,2].any?
=> true
Upvotes: 1