librelist archives

« back to archive

[bamboo]fdt.foreign和fdt.type判断的逻辑问题

[bamboo]fdt.foreign和fdt.type判断的逻辑问题

From:
Uno Young
Date:
2012-03-29 @ 10:03
local makeObject = function (self, data)
-- if data is invalid, return nil
if not isValidInstance(data) then print("[Warning] @makeObject - Object is
invalid."); return nil end
-- XXX: keep id as string for convienent, because http and database are all
string
-- data.id = tonumber(data.id) or data.id
 local fields = self.__fields
for k, fld in pairs(fields) do
-- ensure the correction of field description table
checkType(fld, 'table')
-- convert the number type field
>>> if fld.type == 'number' then
data[k] = tonumber(data[k])
>>> elseif fld.foreign then
local st = fld.st
-- in redis, we don't save MANY foreign key in db, but we want to fill them
when
-- form lua object
if st == 'MANY' then
data[k] = 'FOREIGN MANY ' .. fld.foreign
elseif st == 'FIFO' then
data[k] = 'FOREIGN FIFO ' .. fld.foreign
elseif st == 'ZFIFO' then
data[k] = 'FOREIGN ZFIFO ' .. fld.foreign
end
end
end



当又有type='number‘又有foreign的时候这两处判断有问题