Skip to content

Commit

Permalink
The foreign key in the belongs_to relationship is now only set to the…
Browse files Browse the repository at this point in the history
… value's primary key if the value is an instance of ORM, otherwise the foreign key is set to NULL. Fixes #4420
  • Loading branch information
Rad committed Jan 28, 2012
1 parent bc56b3d commit b577bae
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion classes/kohana/orm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down

0 comments on commit b577bae

Please sign in to comment.