Skip to content
Permalink
Browse files

Make association property() exclude plugin names.

When creating association names that include plugin names we should omit
the plugin name from the hydrated dataset. Instead of 'contacts.users',
we should just get 'users' as an example.
  • Loading branch information...
markstory committed Jan 13, 2014
1 parent 872f78a commit 176717adaadbdc23140325dbffb39b57c662cb0f
@@ -330,7 +330,8 @@ public function property($name = null) {
$this->_propertyName = $name;
}
if ($name === null && !$this->_propertyName) {
$this->_propertyName = Inflector::underscore($this->_name);
list($plugin, $name) = pluginSplit($this->_name);
$this->_propertyName = Inflector::underscore($name);
}
return $this->_propertyName;
}
@@ -82,7 +82,8 @@ public function property($name = null) {
return parent::property($name);
}
if ($name === null && !$this->_propertyName) {
$this->_propertyName = Inflector::underscore(Inflector::singularize($this->_name));
list($plugin, $name) = pluginSplit($this->_name);
$this->_propertyName = Inflector::underscore(Inflector::singularize($name));
}
return $this->_propertyName;
}
@@ -79,7 +79,8 @@ public function property($name = null) {
return parent::property($name);
}
if ($name === null && !$this->_propertyName) {
$this->_propertyName = Inflector::underscore(Inflector::singularize($this->_name));
list($plugin, $name) = pluginSplit($this->_name);
$this->_propertyName = Inflector::underscore(Inflector::singularize($name));
}
return $this->_propertyName;
}
@@ -1294,4 +1294,19 @@ public function testSaveOnlyEntities() {
$association->save($entity);
}
/**
* Test that plugin names are omitted from property()
*
* @return void
*/
public function testPropertyNoPlugin() {
$mock = $this->getMock('Cake\ORM\Table', [], [], '', false);
$config = [
'sourceTable' => $this->article,
'targetTable' => $mock,
];
$association = new BelongsToMany('Contacts.Tags', $config);
$this->assertEquals('tags', $association->property());
}
}
@@ -257,4 +257,19 @@ public function testSaveOnlyEntities() {
$this->assertNull($entity->author_id);
}
/**
* Test that plugin names are omitted from property()
*
* @return void
*/
public function testPropertyNoPlugin() {
$mock = $this->getMock('Cake\ORM\Table', [], [], '', false);
$config = [
'sourceTable' => $this->client,
'targetTable' => $mock,
];
$association = new BelongsTo('Contacts.Companies', $config);
$this->assertEquals('company', $association->property());
}
}
@@ -649,4 +649,20 @@ public function testSaveOnlyEntities() {
$association = new HasMany('Articles', $config);
$association->save($entity);
}
/**
* Test that plugin names are omitted from property()
*
* @return void
*/
public function testPropertyNoPlugin() {
$mock = $this->getMock('Cake\ORM\Table', [], [], '', false);
$config = [
'sourceTable' => $this->author,
'targetTable' => $mock,
];
$association = new HasMany('Contacts.Addresses', $config);
$this->assertEquals('addresses', $association->property());
}
}
@@ -237,4 +237,20 @@ public function testSaveOnlyEntities() {
$this->assertSame($result, $entity);
}
/**
* Test that plugin names are omitted from property()
*
* @return void
*/
public function testPropertyNoPlugin() {
$mock = $this->getMock('Cake\ORM\Table', [], [], '', false);
$config = [
'sourceTable' => $this->user,
'targetTable' => $mock,
];
$association = new HasOne('Contacts.Profiles', $config);
$this->assertEquals('profile', $association->property());
}
}

0 comments on commit 176717a

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