Skip to content

Commit

Permalink
Add test for #4877
Browse files Browse the repository at this point in the history
Appending into list properties does not mark them dirty, one must
manually mark list properties as dirty.

Refs #4877
  • Loading branch information
markstory committed Oct 21, 2014
1 parent d0b12bc commit 0077ebf
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -2772,6 +2772,34 @@ public function testSaveBelongsToMany() {
$this->assertEquals(5, $entity->tags[1]->_joinData->tag_id);
}

/**
* Tests saving belongsToMany records when record exists.
*
* @group save
* @return void
*/
public function testSaveBelongsToManyJoinDataOnExistingRecord() {
$tags = TableRegistry::get('Tags');
$table = TableRegistry::get('Articles');
$table->belongsToMany('Tags');

$entity = $table->find()->contain('Tags')->first();
// not associated to the article already.
$entity->tags[] = $tags->get(3);
$entity->dirty('tags', true);

$this->assertSame($entity, $table->save($entity));

$this->assertFalse($entity->isNew());
$this->assertFalse($entity->tags[0]->isNew());
$this->assertFalse($entity->tags[1]->isNew());
$this->assertFalse($entity->tags[2]->isNew());

$this->assertNotEmpty($entity->tags[0]->_joinData);
$this->assertNotEmpty($entity->tags[1]->_joinData);
$this->assertNotEmpty($entity->tags[2]->_joinData);
}

/**
* Tests saving belongsToMany records can delete all links.
*
Expand Down

0 comments on commit 0077ebf

Please sign in to comment.