Skip to content

Commit

Permalink
Make association names not retain plugins.
Browse files Browse the repository at this point in the history
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 872f78a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ORM/Associations.php
Expand Up @@ -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;
}

Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase/ORM/AssociationsTest.php
Expand Up @@ -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()
*
Expand Down

0 comments on commit 872f78a

Please sign in to comment.