diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-11-14 13:18:06 +0200 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-11-14 14:58:29 +0200 |
commit | e83d6c1b108e3cc27d5962fc059769b30f6ac6eb (patch) | |
tree | 65493337b15b517cda72a490e365d026eb08d8af | |
parent | 37ab52a4c443db888820c49f6d3a463f13132b07 (diff) | |
download | acf2-e83d6c1b108e3cc27d5962fc059769b30f6ac6eb.tar.bz2 acf2-e83d6c1b108e3cc27d5962fc059769b30f6ac6eb.tar.xz |
model: use null backend for computed fields
-rw-r--r-- | acf2/model/field.lua | 1 | ||||
-rw-r--r-- | acf2/model/model.lua | 4 | ||||
-rw-r--r-- | acf2/model/node.lua | 5 | ||||
-rw-r--r-- | acf2/model/root.lua | 2 |
4 files changed, 8 insertions, 4 deletions
diff --git a/acf2/model/field.lua b/acf2/model/field.lua index 3718587..64c727b 100644 --- a/acf2/model/field.lua +++ b/acf2/model/field.lua @@ -45,6 +45,7 @@ M.Field = class(M.Member) function M.Field:init(params) super(self, M.Field):init(params) + if self.compute then self.addr = node.null_addr end if self.editable == nil then self.editable = not self.compute end if self.condition then diff --git a/acf2/model/model.lua b/acf2/model/model.lua index 096019b..5b04001 100644 --- a/acf2/model/model.lua +++ b/acf2/model/model.lua @@ -54,7 +54,7 @@ function M.Action:init(params) if self.field then assert(type(self.field) == 'table') self.field = M.to_field(self.field) - self.field.addr = '/null/action' + self.field.addr = node.null_addr end getmetatable(self).__newindex = function(t, k, v) @@ -163,7 +163,7 @@ function M.Model:init(context) ) end local res = v.func(self, f and f:load()) - if f then mt.txn:set(v.field.addr) end + if f then f:_save() end return res end end diff --git a/acf2/model/node.lua b/acf2/model/node.lua index d014b80..9342e83 100644 --- a/acf2/model/node.lua +++ b/acf2/model/node.lua @@ -16,6 +16,9 @@ local pth = require('acf2.path') local util = require('acf2.util') +function M.null_addr(path, name) return '/null'..pth.join(path, name) end + + M.BoundMember = class() function M.BoundMember:init(parent, name, field) @@ -27,7 +30,7 @@ function M.BoundMember:init(parent, name, field) if type(member) ~= 'function' then return member end local addr = field.addr or pth.escape(name) - if type(addr) == 'function' then addr = addr(pmt.addr) end + if type(addr) == 'function' then addr = addr(pmt.path, name) end return function(self, ...) return member( field, diff --git a/acf2/model/root.lua b/acf2/model/root.lua index 7269e79..a6954af 100644 --- a/acf2/model/root.lua +++ b/acf2/model/root.lua @@ -17,7 +17,7 @@ local setdefault = util.setdefault M.RootModel = model.new() function M.RootModel:init(txn) - object.super(self, M.RootModel):init{txn=txn, path='/', addr='/null/root'} + object.super(self, M.RootModel):init{txn=txn, path='/', addr='/null'} end function M.RootModel:has_permission(user, permission) |