From b577baee991282c9dda19cfb2c6ee04940325cdb Mon Sep 17 00:00:00 2001 From: Rad Date: Sat, 28 Jan 2012 00:02:39 +0000 Subject: [PATCH] The foreign key in the belongs_to relationship is now only set to the value's primary key if the value is an instance of ORM, otherwise the foreign key is set to NULL. Fixes #4420 --- classes/kohana/orm.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/classes/kohana/orm.php b/classes/kohana/orm.php index f596675..79d9e38 100644 --- a/classes/kohana/orm.php +++ b/classes/kohana/orm.php @@ -678,7 +678,9 @@ public function set($column, $value) $this->_related[$column] = $value; // Update the foreign key of this model - $this->_object[$this->_belongs_to[$column]['foreign_key']] = $value->pk(); + $this->_object[$this->_belongs_to[$column]['foreign_key']] = ($value instanceof ORM) + ? $value->pk() + : NULL; $this->_changed[$column] = $this->_belongs_to[$column]['foreign_key']; }