webmcp
changeset 543:a886e263b534
Bugfix regarding 1:1 relations: allow setting one class as primary class (needed to avoid endless recursion in foreign key lookups)
author | jbe |
---|---|
date | Sat Oct 19 18:55:24 2019 +0200 (2019-10-19) |
parents | 99a0f1165ef8 |
children | a93ba2a3858a |
files | libraries/mondelefant/mondelefant.lua |
line diff
1.1 --- a/libraries/mondelefant/mondelefant.lua Sat Oct 19 17:59:28 2019 +0200 1.2 +++ b/libraries/mondelefant/mondelefant.lua Sat Oct 19 18:55:24 2019 +0200 1.3 @@ -1464,6 +1464,7 @@ 1.4 db_class = -- same class returned 1.5 <db_class>:add_reference{ 1.6 mode = mode, -- "11", "1m", "m1", or "mm" (one/many to one/many) 1.7 + primary = primary, -- only needed if mode=="11": set to true only in the referenced (not in the referencing) class 1.8 to = to, -- referenced class (model), optionally as string or function returning the value (avoids autoload) 1.9 this_key = this_key, -- name of key in this class (model) 1.10 that_key = that_key, -- name of key in the other class (model) ("to" argument) 1.11 @@ -1482,6 +1483,7 @@ 1.12 function class_prototype:add_reference(args) 1.13 local selector_generator = args.selector_generator 1.14 local mode = args.mode 1.15 + local primary = args.primary 1.16 local to = args.to 1.17 local this_key = args.this_key 1.18 local that_key = args.that_key 1.19 @@ -1573,7 +1575,7 @@ 1.20 return selector 1.21 end 1.22 } 1.23 - if mode == "m1" or mode == "11" then 1.24 + if mode == "m1" or (mode == "11" and not primary) then 1.25 self.foreign_keys[this_key] = ref 1.26 end 1.27 return self