Merge pull request #9086 from psaintjust/association-plugin-classname

Association plugin classname
This commit is contained in:
Mark Story 2016-07-10 10:18:32 -04:00 committed by GitHub
commit 7763e5d6bc
3 changed files with 13 additions and 8 deletions

View file

@ -1035,13 +1035,13 @@ class Model extends Object implements CakeEventListener {
unset($association[$assoc]); unset($association[$assoc]);
$assoc = $value; $assoc = $value;
$value = array(); $value = array();
if (strpos($assoc, '.') !== false) {
list($plugin, $assoc) = pluginSplit($assoc, true);
$association[$assoc] = array('className' => $plugin . $assoc);
} else {
$association[$assoc] = $value; $association[$assoc] = $value;
} }
if (!isset($value['className']) && strpos($assoc, '.') !== false) {
unset($association[$assoc]);
list($plugin, $assoc) = pluginSplit($assoc, true);
$association[$assoc] = array('className' => $plugin . $assoc) + $value;
} }
$this->_generateAssociation($type, $assoc); $this->_generateAssociation($type, $assoc);

View file

@ -1617,10 +1617,12 @@ class ModelIntegrationTest extends BaseModelTest {
public function testAutoConstructPluginAssociations() { public function testAutoConstructPluginAssociations() {
$Comment = ClassRegistry::init('TestPluginComment'); $Comment = ClassRegistry::init('TestPluginComment');
$this->assertEquals(2, count($Comment->belongsTo), 'Too many associations'); $this->assertEquals(3, count($Comment->belongsTo), 'Too many associations');
$this->assertFalse(isset($Comment->belongsTo['TestPlugin.User'])); $this->assertFalse(isset($Comment->belongsTo['TestPlugin.User']));
$this->assertFalse(isset($Comment->belongsTo['TestPlugin.Source']));
$this->assertTrue(isset($Comment->belongsTo['User']), 'Missing association'); $this->assertTrue(isset($Comment->belongsTo['User']), 'Missing association');
$this->assertTrue(isset($Comment->belongsTo['TestPluginArticle']), 'Missing association'); $this->assertTrue(isset($Comment->belongsTo['TestPluginArticle']), 'Missing association');
$this->assertTrue(isset($Comment->belongsTo['Source']), 'Missing association');
} }
/** /**

View file

@ -2991,7 +2991,10 @@ class TestPluginComment extends CakeTestModel {
'className' => 'TestPlugin.TestPluginArticle', 'className' => 'TestPlugin.TestPluginArticle',
'foreignKey' => 'article_id', 'foreignKey' => 'article_id',
), ),
'TestPlugin.User' 'TestPlugin.User',
'TestPlugin.Source' => array(
'foreignKey' => 'source_id'
)
); );
} }