diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 15f815594..5f56ee09f 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -903,11 +903,12 @@ class Model extends Object { 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); diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index c02e5aee1..2140ae195 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -1289,6 +1289,20 @@ class ModelIntegrationTest extends BaseModelTest { $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 * diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index ae098c530..6a72047c3 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -2709,7 +2709,7 @@ class TestPluginComment extends CakeTestModel { 'className' => 'TestPlugin.TestPluginArticle', 'foreignKey' => 'article_id', ), - 'User' + 'TestPlugin.User' ); }