Skip to content
Permalink
Browse files

Show warning if association property name is same as table field.

  • Loading branch information...
ADmad committed Feb 27, 2016
1 parent 1804d87 commit 2d44ca9e5d70058079215399bce6a6dc88c12ec4
@@ -438,6 +438,14 @@ public function property($name = null)
if ($name === null && !$this->_propertyName) {
list(, $name) = pluginSplit($this->_name);
$this->_propertyName = Inflector::underscore($name);
if (in_array($this->_propertyName, $this->_sourceTable->schema()->columns())) {
$msg = 'Association property name "%s" clashes with field of same name of table "%s".' .
"\n" . 'You should explicitly specify the "propertyName" option.';
trigger_error(
sprintf($msg, $this->_propertyName, $this->_sourceTable->table()),
E_USER_WARNING
);
}
}
return $this->_propertyName;
}
@@ -700,10 +700,12 @@ public function testSaveAssociatedNotEmptyNotIterable()
*/
public function testSaveAssociatedEmptySetSuccess($value)
{
$table = $this->getMock('Cake\ORM\Table', ['table'], [[]]);
$table->schema([]);
$assoc = $this->getMock(
'\Cake\ORM\Association\BelongsToMany',
['_saveTarget', 'replaceLinks'],
['tags']
['tags', ['sourceTable' => $table]]
);
$entity = new Entity([
'id' => 1,
@@ -726,10 +728,12 @@ public function testSaveAssociatedEmptySetSuccess($value)
*/
public function testSaveAssociatedEmptySetUpdateSuccess($value)
{
$table = $this->getMock('Cake\ORM\Table', ['table'], [[]]);
$table->schema([]);
$assoc = $this->getMock(
'\Cake\ORM\Association\BelongsToMany',
['_saveTarget', 'replaceLinks'],
['tags']
['tags', ['sourceTable' => $table]]
);
$entity = new Entity([
'id' => 1,
@@ -755,10 +759,12 @@ public function testSaveAssociatedEmptySetUpdateSuccess($value)
*/
public function testSaveAssociatedWithReplace()
{
$table = $this->getMock('Cake\ORM\Table', ['table'], [[]]);
$table->schema([]);
$assoc = $this->getMock(
'\Cake\ORM\Association\BelongsToMany',
['replaceLinks'],
['tags']
['tags', ['sourceTable' => $table]]
);
$entity = new Entity([
'id' => 1,
@@ -782,10 +788,12 @@ public function testSaveAssociatedWithReplace()
*/
public function testSaveAssociatedWithReplaceReturnFalse()
{
$table = $this->getMock('Cake\ORM\Table', ['table'], [[]]);
$table->schema([]);
$assoc = $this->getMock(
'\Cake\ORM\Association\BelongsToMany',
['replaceLinks'],
['tags']
['tags', ['sourceTable' => $table]]
);
$entity = new Entity([
'id' => 1,
@@ -284,7 +284,8 @@ public function testSaveParentsFiltered()
*/
public function testSaveChildrenFiltered()
{
$table = $this->getMock('Cake\ORM\Table', [], [[]]);
$table = $this->getMock('Cake\ORM\Table', ['table'], [[]]);
$table->schema([]);
$mockOne = $this->getMock(
'Cake\ORM\Association\HasMany',
['saveAssociated'],

0 comments on commit 2d44ca9

Please sign in to comment.
You can’t perform that action at this time.