Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Suggestion: Ohm::Model::fetch for uniques? #232

Open
sirscriptalot opened this issue May 11, 2018 · 2 comments
Open

Feature Suggestion: Ohm::Model::fetch for uniques? #232

sirscriptalot opened this issue May 11, 2018 · 2 comments

Comments

@sirscriptalot
Copy link

sirscriptalot commented May 11, 2018

Hi all,

I was curious if anyone thought a method that fetches records by a unique and an array of values would be useful on Ohm::Model? It would look something like...

    # I'm not a fan of the method name...
    def self.fetch_with(att, values)
      raise Ohm::IndexNotFound unless uniques.include?(att)

      ids = nil
      unique = key[:uniques][att]

      synchronize do
        values.map { |value| redis.queue('HGET', unique, value) }

        ids = redis.commit
      end

      return [] if ids.nil?

      fetch(ids)
    end

There is a point in the application I'm working on that uses something similar, and just wanted to share incase you all might find a generic version of it it useful for everyone.

@soveran
Copy link
Owner

soveran commented May 21, 2018

I love the comment about not being a fan :-)

I think this is interesting. Are you still using it?

@sirscriptalot
Copy link
Author

There is a couple of points I am using something very similar to what I wrote above. Basically the app has some light social features and an example where it can be useful is to look up a collection of users via unique nicknames instead of id.

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

No branches or pull requests

2 participants