Skip to content

Commit

Permalink
Write tests for octobercms#2258
Browse files Browse the repository at this point in the history
Prevent nulling when model fails validation
  • Loading branch information
daftspunk committed Jul 30, 2016
1 parent b6ecc65 commit fdcfe80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/backend/behaviors/RelationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ protected function evalToolbarButtons()
case 'belongsToMany':
return ['create', 'add', 'delete', 'remove'];
case 'morphMany':
return ['create', 'delete'];
return ['create', 'delete'];
case 'hasOne':
case 'morphOne':
case 'belongsTo':
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/plugins/database/BelongsToManyModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public function testSetRelationValue()
$author->roles = null;
$this->assertEquals(0, $author->roles->count());

// Extra nullify checks (still exists in DB until saved)
$author->reloadRelations('roles');
$this->assertEquals(2, $author->roles->count());
$author->save();
$author->reloadRelations('roles');
$this->assertEquals(0, $author->roles->count());

// Deferred in memory
$author->roles = [$role2->id, $role3->id];
$this->assertEquals(2, $author->roles->count());
Expand Down

0 comments on commit fdcfe80

Please sign in to comment.