Skip to content

Commit

Permalink
Fix issue with duplicate associations when using string form.
Browse files Browse the repository at this point in the history
Fixes #2002
  • Loading branch information
markstory committed Sep 18, 2011
1 parent 6a4e755 commit 8d43764
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -903,11 +903,12 @@ protected function _createLinks() {
unset ($this->{$type}[$assoc]);
$assoc = $value;
$value = array();
$this->{$type}[$assoc] = $value;

if (strpos($assoc, '.') !== false) {
list($plugin, $assoc) = pluginSplit($assoc);
$this->{$type}[$assoc] = array('className' => $plugin. '.' . $assoc);
} else {
$this->{$type}[$assoc] = $value;
}
}
$this->_generateAssociation($type, $assoc);
Expand Down
14 changes: 14 additions & 0 deletions lib/Cake/Test/Case/Model/ModelIntegrationTest.php
Expand Up @@ -1289,6 +1289,20 @@ public function testAutoConstructAssociations() {
$this->assertEqual($TestFakeModel->Tag->name, 'Tag');
}

/**
* test creating associations with plugins. Ensure a double alias isn't created
*
* @return void
*/
public function testAutoConstructPluginAssociations() {
$Comment = ClassRegistry::init('TestPluginComment');

$this->assertEquals(2, count($Comment->belongsTo), 'Too many associations');
$this->assertFalse(isset($Comment->belongsTo['TestPlugin.User']));
$this->assertTrue(isset($Comment->belongsTo['User']), 'Missing association');
$this->assertTrue(isset($Comment->belongsTo['TestPluginArticle']), 'Missing association');
}

/**
* test Model::__construct
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Model/models.php
Expand Up @@ -2709,7 +2709,7 @@ class TestPluginComment extends CakeTestModel {
'className' => 'TestPlugin.TestPluginArticle',
'foreignKey' => 'article_id',
),
'User'
'TestPlugin.User'
);
}

Expand Down

0 comments on commit 8d43764

Please sign in to comment.