maccman / supermodel

Ruby in-memory models

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

return nil when use 'find_by_xxx'

shaoyangyu opened this issue · comments

Hello
I tried use SuperModel to connect Redis with AR , but I found it always return "nil" when use 'find_by_xxx' like below, any idea or it's my fault to use in such way ?

require "redis"
require 'supermodel'
class Hello < SuperModel::Base
include SuperModel::Redis::Model
attributes:yyy
end

h=Hello.new
h.yyy='test'
h.save

p Hello.find_by_yyy('test') #=>nil

p Hello.all #=><Hello:0x2e4b680 @new_record=false, @attributes={"yyy"=>"test", "id"=>1}, @changed_attributes={"yyy"=>nil}>

You need to add indexes.

It works when mark the attribute as index to use find_by_xxx. :)
Thanks a lot.