diff --git a/php-classes/ActiveRecord.class.php b/php-classes/ActiveRecord.class.php index 153e123e8..a9c972197 100644 --- a/php-classes/ActiveRecord.class.php +++ b/php-classes/ActiveRecord.class.php @@ -2628,7 +2628,11 @@ protected function _setRelationshipValue($relationship, $value) } if ($related->isA($rel['class'])) { - if ($existing = $rel['linkClass']::getByWhere([$rel['linkLocal'] => $this->getValue($rel['local']), $rel['linkForeign'] => $related->getValue($rel['foreign'])])) { + $conditions = is_callable($rel['conditions']) ? call_user_func($rel['conditions'], $this, $relationship, $rel) : $rel['conditions']; + $conditions[$rel['linkLocal']] = $this->getValue($rel['local']); + $conditions[$rel['linkForeign']] = $related->getValue($rel['foreign']); + + if ($existing = $rel['linkClass']::getByWhere($conditions)) { $set[] = $existing; } else { $set[] = $rel['linkClass']::create([