- if model[name] and not model[nameOrig] then
- model[nameOrig] = model[name]
- model[name] = function(self, ...)
+ -- We decorate the class and not the object, otherwise we cannot
+ -- save models anymore.
+
+ if rawget(model, name) then
+ error('We decorate the class, not the objects, and there is a `'
+ .. name
+ .. '\' function in '
+ .. tostring(model))
+ end
+
+ local toDecorate = getmetatable(model)
+
+ if toDecorate[name] and not toDecorate[nameOrig] then
+ toDecorate[nameOrig] = toDecorate[name]
+ toDecorate[name] = function(self, ...)