diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-10-04 08:23:19 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-10-04 13:47:42 +0300 |
commit | 33dd854bfd391ba0a6f3ead2bc8ac32468793883 (patch) | |
tree | b06502fc77b7060b3b25587ba1f6623b3b1cb2cd /acf | |
parent | 98ecf5591f98399d766fec6fa7ef5e883cf3da70 (diff) | |
download | aconf-33dd854bfd391ba0a6f3ead2bc8ac32468793883.tar.bz2 aconf-33dd854bfd391ba0a6f3ead2bc8ac32468793883.tar.xz |
model: options argument for Field.load
Diffstat (limited to 'acf')
-rw-r--r-- | acf/model/field.lua | 10 | ||||
-rw-r--r-- | acf/model/init.lua | 4 | ||||
-rw-r--r-- | acf/model/model.lua | 7 | ||||
-rw-r--r-- | acf/model/node.lua | 4 |
4 files changed, 14 insertions, 11 deletions
diff --git a/acf/model/field.lua b/acf/model/field.lua index 707cde3..7dc20a1 100644 --- a/acf/model/field.lua +++ b/acf/model/field.lua @@ -181,13 +181,15 @@ end function M.TreeNode:topology(context) local res = super(self, M.TreeNode):topology(context) res[1].type = 'table' - util.extend(res, node.topology(self:load(context, true))) + util.extend(res, node.topology(self:load(context, {create=true}))) return res end -function M.TreeNode:load(context, create) +function M.TreeNode:load(context, options) if context.txn and not ( - create or self.create or context.txn:get(context.addr) + ( + options and options.create + ) or self.create or context.txn:get(context.addr) ) then return end return self.itype(context, self.iparams) end @@ -209,7 +211,7 @@ function M.TreeNode:save(context, value) end context.txn:set(context.addr, {}) - local new = self:load(context, true) + local new = self:load(context, {create=true}) local errors = err.ErrorDict() for k, v in node.pairs(value) do diff --git a/acf/model/init.lua b/acf/model/init.lua index 1e7a920..653464d 100644 --- a/acf/model/init.lua +++ b/acf/model/init.lua @@ -156,9 +156,9 @@ function M.Collection:auto_ui_name(name) return super(self, M.Collection):auto_ui_name(name) end -function M.Collection:load(context, create) +function M.Collection:load(context, options) if not self.iparams.field then self.iparams.field = to_field(self.type) end - return super(self, M.Collection):load(context, create) + return super(self, M.Collection):load(context, options) end diff --git a/acf/model/model.lua b/acf/model/model.lua index 026ada6..6878497 100644 --- a/acf/model/model.lua +++ b/acf/model/model.lua @@ -135,20 +135,21 @@ function M.Model:init(context) return res end - function mt.load(k, create) + function mt.load(k, options) local v = mt.class[k] + local create = options and options.create if isinstance(v, Field) then v = BoundMember(self, k, v) if v.compute then return v:compute() end - return v:load(create) + return v:load{create=create} end assert(mt.txn) if isinstance(v, M.Action) then local f = v.field and BoundMember(self, k, v.field) - if create then return f and f:load(true) end + if create then return f and f:load{create=true} end return function(var) if f then f:save(var) diff --git a/acf/model/node.lua b/acf/model/node.lua index dfb919d..5fa3a39 100644 --- a/acf/model/node.lua +++ b/acf/model/node.lua @@ -52,7 +52,7 @@ function M.TreeNode:init(context) util.update(mt, context) mt.meta = {} - function mt.get(k, create) return mt.load(k, create) end + function mt.get(k, create) return mt.load(k, {create=create}) end if not mt.txn then return end @@ -156,7 +156,7 @@ function M.Collection:init(context, params) return M.BoundMember(self, name, params.field) end - function mt.load(k, create) return mt.member(k):load(create) end + function mt.load(k, options) return mt.member(k):load(options) end if not mt.txn then return end |