soveran / ohm

Object-Hash Mapping for Redis

Home Page:http://ohm.keyvalue.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Suggestion: `Ohm::Model::fetch` for uniques?

sirscriptalot opened this issue · comments

commented

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.

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

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

commented

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.