Let's say we have a simple Mongoid model:
class Article
include SimpleEnum::Mongoid
VALID_TYPES = { blog: 0, vlog: 1, xlog: 2 }
# ...
as_enum :type, VALID_TYPES, source: :type
end
As far as I can see (correct me if I'm wrong!), it's not possible to query using a selector that takes the symbol corresponding to a value of an enum, like this:
Article.where(type: :blog).count
while instead is possible to do this:
Article.where(type: 0).count
Article.where(type: Article::VALID_TYPES[:blog]).count # or this, don't like it though
I'm aware of the fact that it's possible to use chained selectors, like this:
but in our codebase we often build selectors as hashes that are passed to instances of different classes.
Besides this maybe not being the best approach of all times, IMHO it'd be very beneficial to be able to consume the gem in a consistent way, always passing the symbol (key of the hash), not the value.
Do you think it's a complicated matter? Can you give me pointers to where to look at, so maybe I can submit a PR?
Let's say we have a simple Mongoid model:
As far as I can see (correct me if I'm wrong!), it's not possible to query using a selector that takes the symbol corresponding to a value of an enum, like this:
while instead is possible to do this:
I'm aware of the fact that it's possible to use chained selectors, like this:
but in our codebase we often build selectors as hashes that are passed to instances of different classes.
Besides this maybe not being the best approach of all times, IMHO it'd be very beneficial to be able to consume the gem in a consistent way, always passing the symbol (key of the hash), not the value.
Do you think it's a complicated matter? Can you give me pointers to where to look at, so maybe I can submit a PR?