diff options
Diffstat (limited to 'acf/model/model.lua')
-rw-r--r-- | acf/model/model.lua | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/acf/model/model.lua b/acf/model/model.lua index 6a9a843..aa27312 100644 --- a/acf/model/model.lua +++ b/acf/model/model.lua @@ -79,6 +79,13 @@ function Model:init(txn, path, addr) return util.map(function(f) return f.name end, mt.meta.fields) end + function mt.validate() + for _, name in ipairs(mt.members()) do + local field = mt.field(name) + if not field.compute then field:validate_saved() end + end + end + function mt.__index(t, k) local f = mt.field(k) if f then @@ -93,14 +100,4 @@ function Model:init(txn, path, addr) if not f then raise(mt.path, 'Field named '..k..' does not exist') end f:save(v) end - - txn.validate[mt.path] = function() self:validate() end -end - -function Model:validate() - local mt = getmetatable(self) - for _, name in ipairs(mt.members()) do - local field = mt.field(name) - if not field.compute then field:validate_saved() end - end end |