Is it possible to fetch all object from array?
urbanczykd opened this issue · 6 comments
let's say that I have in redis something like that
Os.create(:me => 1, :color => 'blue')
Os.create(:me => 2, :color => 'blue')
Os.create(:me => 3, :color => 'red')
Os.create(:me => 4, :color => 'green')
and I would like to fetch this data somehow like that
Os.all.find(:me => [2,3])
so in this case i should get 2 objects with color ble and red
and whould be just awsom If i could get
Os.all.find(:me => [2,3], :color => 'blue')
and gets only object with me = 2
is it possible and this example is just missing in documentation or no :/ help :D
Maybe:
def fetch(us, color)
res = self.class.find(me: us.pop)
us.each do |me_or_you|
res = res.union(me: me_or_you)
end
res.find(color: color)
end
What about this:
Os.find(me: 2).union(me: 3).find(color: "blue")
yes this works just fine but i'm affraid that in my case this 'me' sometimes can be more then 100 passing as array would be more useful but maybe I will just write own method for this case if this feature is not on project road map it's better if I will do it only for my project
I just released a new version that you can use for solving that problem. There's now a new filter called combine
, you can use it like this:
Os.find(color: "blue").combine(me: [2, 3])
thanks much I will update 1.3.x because our project it's still on ruby 1.8.x and because of require_relative it can't work but i will move this method to 1.3.x and maybe it will be possible to create new 1.3 version ?
I backported the feature and released the 1.4.0 version. If it works for you, you can start following the 1.4.x branch.