summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--acf2/model/field.lua4
-rw-r--r--acf2/model/model.lua7
2 files changed, 5 insertions, 6 deletions
diff --git a/acf2/model/field.lua b/acf2/model/field.lua
index 6277ec9..777a311 100644
--- a/acf2/model/field.lua
+++ b/acf2/model/field.lua
@@ -111,7 +111,9 @@ end
function M.Field:load(context)
if not context.txn then return setmetatable({}, context) end
- local value = self:_load(context)
+ local value
+ if self.compute then value = self:compute(context) end
+ if value == nil then value = self:_load(context) end
if value == nil then return self.default end
return value
end
diff --git a/acf2/model/model.lua b/acf2/model/model.lua
index 04d031a..7d026da 100644
--- a/acf2/model/model.lua
+++ b/acf2/model/model.lua
@@ -142,10 +142,7 @@ function M.Model:init(context)
local v = mt.class[k]
if isinstance(v, Field) then
- v = BoundMember(self, k, v)
- local res = v:load(options)
- if res == nil and v.compute then return v:compute() end
- return res
+ return BoundMember(self, k, v):load(options)
end
assert(mt.txn)
@@ -204,7 +201,7 @@ function M.Model:init(context)
function mt.validate()
for _, f in ipairs(_members(Field)) do
- if f.editable and not f.compute then
+ if f.editable then
if mt.match(f.condition or {}) then f:validate_saved()
else f:_save() end
end