Skip to content

Ability to create selectors passing symbols #95

Description

@lucke84

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:

Article.blogs.count

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions