Bug Report #2322
ORM __set() method does not flag $_belongs_to data as $_changed, thus will not include it in save()
| Status: | Closed | Start date: | 11/07/2009 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | Modules:ORM | |||
| Target version: | v3.0.2 | |||
| Resolution: | fixed | Points: |
Description
Even after setting $orm->field where field is a $_belongs_to alias, ORM does not save the value to database upon calling save(). It turned out that in __set() method, the 'if' block that handles $_belongs_to alias is missing $this->_changed, causing the alias to not been included in the insert/update statement to the database.
Sample:
$exercise = ORM::factory('exercise');
$exercise->title = 'Test2';
$exercise->user = ORM::factory('user', array('username'=>'user1'));
$exercise->save(); // this will only invoke "INSERT INTO `exercises` (`title`) VALUES ('Test2')"
The model:
class Model_Exercise extends ORM {
protected $_belongs_to = array(
'user' => array(),
);
}
This can be fixed by adding the following line in ORM::__set() method
$this->_changed[$column] = $this->_belongs_to[$column]['foreign_key'];
Inside
elseif (isset($this->_belongs_to[$column]))
{
}
Associated revisions
Fixing #2322
History
Updated by Woody Gilk about 2 years ago
- Category set to Modules:ORM
- Status changed from New to Assigned
- Assignee set to John Heathco
- Target version changed from v3.0.1 to v3.0.2
Updated by John Heathco about 2 years ago
- Status changed from Assigned to Closed
- Resolution set to fixed
Updated by Woody Gilk about 2 years ago
- Project changed from Kohana v3.x to 78
- Category deleted (
Modules:ORM) - Target version deleted (
v3.0.2)
Updated by Woody Gilk about 2 years ago
- Project changed from 78 to Kohana v3.x
Updated by Woody Gilk about 2 years ago
- Category set to Modules:ORM
Updated by Woody Gilk about 2 years ago
- Target version set to v3.0.2