# HG changeset patch # User jbe # Date 1571504124 -7200 # Node ID a886e263b534cae593cf37e5a060896c413e777b # Parent 99a0f1165ef86b33c623474af10eb0d1c40e0d23 Bugfix regarding 1:1 relations: allow setting one class as primary class (needed to avoid endless recursion in foreign key lookups) diff -r 99a0f1165ef8 -r a886e263b534 libraries/mondelefant/mondelefant.lua --- a/libraries/mondelefant/mondelefant.lua Sat Oct 19 17:59:28 2019 +0200 +++ b/libraries/mondelefant/mondelefant.lua Sat Oct 19 18:55:24 2019 +0200 @@ -1464,6 +1464,7 @@ db_class = -- same class returned :add_reference{ mode = mode, -- "11", "1m", "m1", or "mm" (one/many to one/many) + primary = primary, -- only needed if mode=="11": set to true only in the referenced (not in the referencing) class to = to, -- referenced class (model), optionally as string or function returning the value (avoids autoload) this_key = this_key, -- name of key in this class (model) that_key = that_key, -- name of key in the other class (model) ("to" argument) @@ -1482,6 +1483,7 @@ function class_prototype:add_reference(args) local selector_generator = args.selector_generator local mode = args.mode + local primary = args.primary local to = args.to local this_key = args.this_key local that_key = args.that_key @@ -1573,7 +1575,7 @@ return selector end } - if mode == "m1" or mode == "11" then + if mode == "m1" or (mode == "11" and not primary) then self.foreign_keys[this_key] = ref end return self