Skip to content
Permalink
Browse files

Make association names not retain plugins.

Creating associations in plugins should not retain aliases like
'Photos.Photos'. Instead the plugin segment should be dropped and the
association should just be called 'Photos'. This keeps behavior
consistent with previous releases and avoids annoying problems when
trying to contain() association names with `.` in them.
  • Loading branch information...
markstory committed Jan 13, 2014
1 parent 2a82421 commit 872f78a1a0b2996d83940127bf594d6dc0d49604
Showing with 20 additions and 1 deletion.
  1. +5 −1 src/ORM/Associations.php
  2. +15 −0 tests/TestCase/ORM/AssociationsTest.php
@@ -36,11 +36,15 @@ class Associations {
/**
* Add an association to the collection
*
* If the alias added contains a `.` the part preceding the `.` will be dropped.
* This makes using plugins simpler as the Plugin.Class syntax is frequently used.
*
* @param string $alias The association alias
* @param Association The association to add.
* @return void
* @return Association The association object being added.
*/
public function add($alias, Association $association) {
list($plugin, $alias) = pluginSplit($alias);
return $this->_items[strtolower($alias)] = $association;
}
@@ -62,6 +62,21 @@ public function testAddHasRemoveAndGet() {
$this->assertNull($this->associations->get('Users'));
}
/**
* Test associations with plugin names.
*
* @return void
*/
public function testAddHasRemoveGetWithPlugin() {
$this->assertFalse($this->associations->has('Photos.Photos'));
$this->assertFalse($this->associations->has('Photos'));
$belongsTo = new BelongsTo([]);
$this->assertSame($belongsTo, $this->associations->add('Photos.Photos', $belongsTo));
$this->assertTrue($this->associations->has('Photos'));
$this->assertFalse($this->associations->has('Photos.Photos'));
}
/**
* Test keys()
*

0 comments on commit 872f78a

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