diff options
Diffstat (limited to 'acf/model')
-rw-r--r-- | acf/model/field.lua | 5 | ||||
-rw-r--r-- | acf/model/init.lua | 8 | ||||
-rw-r--r-- | acf/model/node.lua | 4 |
3 files changed, 9 insertions, 8 deletions
diff --git a/acf/model/field.lua b/acf/model/field.lua index 26d4621..7af0698 100644 --- a/acf/model/field.lua +++ b/acf/model/field.lua @@ -75,7 +75,7 @@ function Field:meta(context) end function Field:load(context) - local value = context.txn:get(context.addr) + local value = context.txn:get(context.addr, self.dtype) if value == nil then return self.default end return value end @@ -94,7 +94,6 @@ end function Field:validate(context, value) end function Field:save(context, value) - -- 2nd argument currenly not much used by backends context.txn:set(context.addr, self.dtype, self:_validate(context, value)) end @@ -150,6 +149,6 @@ function Model:init(params) end function Model:load(context, create) - if not create and not context.txn:get(context.addr) then return end + if not (create or context.txn:get(context.addr, 'table')) then return end return self.model(context) end diff --git a/acf/model/init.lua b/acf/model/init.lua index 00fc7aa..1bc190d 100644 --- a/acf/model/init.lua +++ b/acf/model/init.lua @@ -129,7 +129,8 @@ function Reference:meta(context) local txn = context.txn local objs = txn:get( - node.addr(relabel('system', txn.search, txn, res.scope)) + node.addr(relabel('system', txn.search, txn, res.scope)), + 'table' ) or {} res.choice = map(function(p) return pth.join(res.scope, p) end, objs) res['ui-choice'] = objs @@ -209,15 +210,16 @@ Mixed = class(Collection) function Mixed:init(params) params.type = Mixed super(self, Mixed):init(params, node.Mixed) + self.pfield = Field() end function Mixed:load(context) - local value = Primitive.load(self, context) + local value = self.pfield:load(context) if type(value) == 'table' then return super(self, Mixed):load(context) end return value end function Mixed:save(context, value) if type(value) == 'table' then super(self, Mixed):save(context, value) - else Primitive.save(self, context, value) end + else self.pfield:save(context, value) end end diff --git a/acf/model/node.lua b/acf/model/node.lua index 8028bcb..afc3e0f 100644 --- a/acf/model/node.lua +++ b/acf/model/node.lua @@ -114,10 +114,10 @@ function Collection:init(context, params) function mt.valid_member(name) return true end function mt.mmeta(name) return mt.meta.members end - function mt.members() return mt.txn:get(mt.addr) or {} end + function mt.members() return mt.txn:get(mt.addr, 'table') or {} end function mt.validate() - if params.required and #mt.txn:get(mt.addr) == 0 then + if params.required and #mt.members() == 0 then raise(mt.path, 'Collection cannot be empty') end end |