{"action":"created","issue":{"url":"https://api.github.com/repos/lwe/simple_enum/issues/95","labels_url":"https://api.github.com/repos/lwe/simple_enum/issues/95/labels{/name}","comments_url":"https://api.github.com/repos/lwe/simple_enum/issues/95/comments","events_url":"https://api.github.com/repos/lwe/simple_enum/issues/95/events","html_url":"https://github.com/lwe/simple_enum/issues/95","id":54884164,"number":95,"title":"Ability to create selectors passing symbols","user":{"login":"lucke84","id":783937,"avatar_url":"https://avatars.githubusercontent.com/u/783937?v=3","gravatar_id":"","url":"https://api.github.com/users/lucke84","html_url":"https://github.com/lucke84","followers_url":"https://api.github.com/users/lucke84/followers","following_url":"https://api.github.com/users/lucke84/following{/other_user}","gists_url":"https://api.github.com/users/lucke84/gists{/gist_id}","starred_url":"https://api.github.com/users/lucke84/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucke84/subscriptions","organizations_url":"https://api.github.com/users/lucke84/orgs","repos_url":"https://api.github.com/users/lucke84/repos","events_url":"https://api.github.com/users/lucke84/events{/privacy}","received_events_url":"https://api.github.com/users/lucke84/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/lwe/simple_enum/labels/enhancement","name":"enhancement","color":"02d7e1"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-01-20T13:42:53Z","updated_at":"2015-02-25T17:46:27Z","closed_at":null,"body":"Let's say we have a simple *Mongoid* model:\r\n```ruby\r\nclass Article \r\n  include SimpleEnum::Mongoid\r\n\r\n  VALID_TYPES = { blog: 0, vlog: 1, xlog: 2 }\r\n\r\n  # ...\r\n  as_enum :type, VALID_TYPES, source: :type\r\nend\r\n```\r\n\r\nAs 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:\r\n```ruby\r\nArticle.where(type: :blog).count\r\n```\r\n\r\nwhile instead is possible to do this:\r\n```ruby\r\nArticle.where(type: 0).count\r\nArticle.where(type: Article::VALID_TYPES[:blog]).count # or this, don't like it though\r\n```\r\n\r\nI'm aware of the fact that it's possible to use chained selectors, like this:\r\n```ruby\r\nArticle.blogs.count\r\n```\r\n\r\nbut in our codebase we often build selectors as hashes that are passed to instances of different classes. \r\n\r\nBesides 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.\r\n\r\nDo you think it's a complicated matter? Can you give me pointers to where to look at, so maybe I can submit a PR?"},"comment":{"url":"https://api.github.com/repos/lwe/simple_enum/issues/comments/76015589","html_url":"https://github.com/lwe/simple_enum/issues/95#issuecomment-76015589","issue_url":"https://api.github.com/repos/lwe/simple_enum/issues/95","id":76015589,"user":{"login":"lucke84","id":783937,"avatar_url":"https://avatars.githubusercontent.com/u/783937?v=3","gravatar_id":"","url":"https://api.github.com/users/lucke84","html_url":"https://github.com/lucke84","followers_url":"https://api.github.com/users/lucke84/followers","following_url":"https://api.github.com/users/lucke84/following{/other_user}","gists_url":"https://api.github.com/users/lucke84/gists{/gist_id}","starred_url":"https://api.github.com/users/lucke84/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucke84/subscriptions","organizations_url":"https://api.github.com/users/lucke84/orgs","repos_url":"https://api.github.com/users/lucke84/repos","events_url":"https://api.github.com/users/lucke84/events{/privacy}","received_events_url":"https://api.github.com/users/lucke84/received_events","type":"User","site_admin":false},"created_at":"2015-02-25T17:46:27Z","updated_at":"2015-02-25T17:46:27Z","body":"@Startouf as per the nature of the gem, I was imagining it used for DB queries only, otherwise a simple `to_hash` would be enough. \r\n\r\nAlso, in my mind, the method should also take care of dealing with lists of values and translate them into the right DB selector, e.g.:\r\n\r\n```\r\nPerson.enums_to_selector(gender: :male)             # --> { gender: 0 }\r\nPerson.enums_to_selector(gender: [:male, :female])  # --> { :gender.in => [0, 1] }\r\n```\r\n\r\nHence the name I came up with.\r\n\r\nDoes this make sense to everybody?"}}