Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed hash loading bug

  • Loading branch information...
commit 91b7fb3649d8a120c8329949c0b92272914488ef 1 parent f0654f5
@slact authored
Showing with 9 additions and 6 deletions.
  1. +5 −3 lohm/hash.lua
  2. +1 −1  lohm/index.lua
  3. +3 −2 test.lua
View
8 lohm/hash.lua
@@ -37,18 +37,20 @@ function initialize(prototype, arg)
assert(hgetall_res.queued==true)
local raw_loaded_data = coroutine.yield()
local loaded_data = raw_loaded_data[1]
-
+
+ --debug.print("LOAD", self:getKey(), raw_loaded_data, self)
+ --print(debug.traceback())
+
if not next(loaded_data) then
return nil, "Redis hash at " .. self:getKey() .. " not found."
else
for k, v in pairs(loaded_data) do
deletable_attributes[self][k]=true
- if not attributes[k] then
+ if not rawget(attributes, k) then
self[k]=v
end
end
end
- return self
end):addCallback('save', function(self, redis)
local key = self:getKey()
assert(key, "Tried to save data without a key or key assignment scheme. You can't do that.")
View
2  lohm/index.lua
@@ -119,7 +119,7 @@ function new(model, name)
return self
end,
getSet = function(self, val)
- return self.model:new(nil, hash(val), false)
+ return self.model:new(nil, hash(val), true)
end,
getSetKey = function(self, val)
return (self.model:key(hash(val)))
View
5 test.lua
@@ -129,7 +129,7 @@ context("Basic manipulation", function()
m:set('barbar','baz'):save()
assert(m:getId()==id)
local checkM = assert(Model:findOne(id))
- assert_true( checkM.barbar=="baz" )
+ assert_true( rawget(checkM,'barbar')=="baz" )
assert_true( "barbar"==checkM.foo )
assert(checkM:delete())
local notfound = Model[tonumber(id)]
@@ -182,6 +182,8 @@ context("Indexing", function()
end
assert_equal(#assert(M:findByAttr{i3=1})+#assert(M:findByAttr{i3=2}), 300)
local res = M:findByAttr(findey)
+
+ assert_equal(res[1].i3, tostring(findey.i3))
assert_equal(#res, 1)
assert_equal(res[1].i3, tostring(findey.i3))
for i, v in pairs(res[1]) do
@@ -194,7 +196,6 @@ context("Indexing", function()
experiment_one.i3=nil
experiment_one:save()
- os.exit(23)
end)
end)
Please sign in to comment.
Something went wrong with that request. Please try again.