Ticket #1419 (closed defect: fixed)

Opened 10 months ago

Last modified 7 months ago

Related Objects are not saved if Parent is not Modified.

Reported by: buennagelj Owned by: romanb
Priority: major Milestone: 1.1.0-ALPHA1
Component: Relations Version: 1.0.0
Severity: Keywords:
Cc: Has Test: no
Status: Pending Core Response Has Patch: no

Description (last modified by jwage) (diff)

When I load a graph of related objects (e.g. One-To-Many) and change one of the child objects, the changes are not saved when I call save() on the root object.

This is because of a safeguard against endless recursion in the UnitOfWork?, that will stop traversing the object graph as soon as it finds an object that is not modified. The easiest fix would be to remove the check for isModified(), but then you'd be vulnerable to cyclic relationship graphs. I don't know how to cleverly fix this...

Change History

Changed 10 months ago by romanb

  • milestone set to 1.0.1

Changed 10 months ago by jwage

  • status changed from new to closed
  • resolution set to worksforme

In r4895 I added coverage for this and it is working for me. Going to close this ticket as worksforme unless you can help me make the test fail. Thanks, Jon

Changed 8 months ago by dmuldia

  • status changed from closed to reopened
  • resolution worksforme deleted

Encountered same problem. Parent class Address doesn't cascade save to child class Coordinate, when only Coordinate has been changed.

Address:

public function setTableDefinition() {

// Options $this->option('charset', 'utf8'); $this->option('type', 'InnoDB');

// Columns

$this->hasColumn('id', 'integer', 4, array('notnull' => true,

'primary' => true, 'autoincrement' => true));

$this->hasColumn('country_id', 'integer', 4);

$this->hasColumn('county_id', 'integer', 4);

$this->hasColumn('city_id', 'integer', 4);

$this->hasColumn('region_id', 'integer', 4);

$this->hasColumn('zip', 'string', 32); $this->hasColumn('street', 'string', 128);

} public function setUp() {

$this->hasOne('Country', array('local' => 'country_id',

'foreign' => 'id', 'onDelete' => 'SET NULL'));

$this->hasOne('County', array('local' => 'county_id',

'foreign' => 'id', 'onDelete' => 'SET NULL'));

$this->hasOne('City', array('local' => 'city_id',

'foreign' => 'id', 'onDelete' => 'SET NULL'));

$this->hasOne('Region', array('local' => 'region_id',

'foreign' => 'id', 'onDelete' => 'SET NULL'));

$this->hasOne('Coordinate', array('local' => 'id',

'foreign' => 'address_id'));

$this->hasOne('Establishment', array('local' => 'id',

'foreign' => 'address_id', 'cascade' => array('delete' => true)));

$this->hasOne('Company', array('local' => 'id',

'foreign' => 'address_id', 'cascade' => array('delete' => true)));

}

Coordinate:

public function setTableDefinition() {

// Options $this->option('charset', 'utf8'); $this->option('type', 'InnoDB');

// Columns

$this->hasColumn('id', 'integer', 4, array('notnull' => true,

'primary' => true, 'autoincrement' => true));

$this->hasColumn('address_id', 'integer', 4);

$this->hasColumn('address_string', 'string', 255, array('unique' => true));

$this->hasColumn('lat', 'float'); $this->hasColumn('lng', 'float');

}

public function setUp() {

$this->hasOne('Address', array('local' => 'address_id',

'foreign' => 'id', 'onDelete' => 'cascade'));

}

Changed 8 months ago by jwage

Can you paste your code so it is readable? Or post it as a test case?

Changed 8 months ago by jwage

  • milestone changed from 1.0.1 to 1.0.5

Changed 7 months ago by jwage

  • status changed from reopened to closed
  • resolution set to fixed
  • description modified (diff)

This was fixed in 1.1. Was cannot make this change in 1.0 as it changes the behavior.

Changed 7 months ago by jwage

  • milestone changed from 1.0.5 to 1.1.0-ALPHA1
Note: See TracTickets for help on using tickets.