librelist archives

« back to archive

[bamboo]hasForeign的bug

[bamboo]hasForeign的bug

From:
Uno Young
Date:
2012-03-22 @ 02:43
 hasForeign = function (self, field, obj)
I_AM_INSTANCE(self)
checkType(field, 'string')
local fld = self.__fields[field]
assert(fld, ("[Error] Field %s doesn't be defined!"):format(field))
assert(fld.foreign, ("[Error] This field %s is not a foreign
field."):format(field))
assert( fld.st, ("[Error] No store type setting for this foreign field
%s."):format(field))
assert(fld.foreign == 'ANYSTRING' or obj.id, "[Error] This object doesn't
contain id, it's not a valid object!")
assert(fld.foreign == 'ANYSTRING' or fld.foreign == 'UNFIXED' or
fld.foreign == getClassName(obj),
   ("[Error] The foreign model (%s) of this field %s doesn't equal the
object's model %s."):format(fld.foreign, field, getClassName(obj) or ''))
if isFalse(self[field]) then return nil end

local new_id
if isStrOrNum(obj) then
-- obj is id or anystring
new_id = tostring(obj)
else
checkType(obj, 'table')
if fld.foreign == 'UNFIXED' then
new_id = getNameIdPattern(self)
else
new_id = tostring(obj.id)
end
end

if fld.st == "ONE" then
return self[field] == new_id
else
local key = getFieldPattern(self, field)
local store_module = getStoreModule(fld.st)


>>> store_module.has(key, new_id)
改为 return store_module.has(key, new_id)

end

return false
end;

Re: [bamboo]hasForeign的bug

From:
Tang Daogang
Date:
2012-03-24 @ 01:55
已修改。

On Thu, Mar 22, 2012 at 10:43 AM, Uno Young <littlehaker@gmail.com> wrote:

> hasForeign = function (self, field, obj)
> I_AM_INSTANCE(self)
> checkType(field, 'string')
>  local fld = self.__fields[field]
> assert(fld, ("[Error] Field %s doesn't be defined!"):format(field))
>  assert(fld.foreign, ("[Error] This field %s is not a foreign
> field."):format(field))
> assert( fld.st, ("[Error] No store type setting for this foreign field
> %s."):format(field))
>  assert(fld.foreign == 'ANYSTRING' or obj.id, "[Error] This object
> doesn't contain id, it's not a valid object!")
>  assert(fld.foreign == 'ANYSTRING' or fld.foreign == 'UNFIXED' or
> fld.foreign == getClassName(obj),
>    ("[Error] The foreign model (%s) of this field %s doesn't equal the
> object's model %s."):format(fld.foreign, field, getClassName(obj) or ''))
>  if isFalse(self[field]) then return nil end
>
> local new_id
>  if isStrOrNum(obj) then
> -- obj is id or anystring
> new_id = tostring(obj)
>  else
> checkType(obj, 'table')
> if fld.foreign == 'UNFIXED' then
>  new_id = getNameIdPattern(self)
> else
> new_id = tostring(obj.id)
>  end
> end
>
> if fld.st == "ONE" then
>  return self[field] == new_id
> else
> local key = getFieldPattern(self, field)
>  local store_module = getStoreModule(fld.st)
>
>
> >>> store_module.has(key, new_id)
> 改为 return store_module.has(key, new_id)
>
> end
>
>  return false
> end;
>



-- 
Nothing is impossible.