Fixing issues with plugin models used in habtm 'with' keys. Fixes #1548

This commit is contained in:
mark_story 2011-03-19 08:45:10 -04:00
parent 9ae8dcafdc
commit 6d2b31d4d1
2 changed files with 18 additions and 1 deletions

View file

@ -1959,7 +1959,7 @@ class Model extends Object {
*/
protected function _deleteLinks($id) {
foreach ($this->hasAndBelongsToMany as $assoc => $data) {
$joinModel = $data['with'];
list($plugin, $joinModel) = pluginSplit($data['with']);
$records = $this->{$joinModel}->find('all', array(
'conditions' => array_merge(array($this->{$joinModel}->escapeField($data['foreignKey']) => $id)),
'fields' => $this->{$joinModel}->primaryKey,

View file

@ -533,6 +533,23 @@ class ModelDeleteTest extends BaseModelTest {
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
}
/**
* test that a plugin model as the 'with' model doesn't have issues
*
* @return void
*/
function testDeleteLinksWithPLuginJoinModel() {
$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
$Article =& new Article();
$Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')), false);
unset($Article->Tag, $Article->ArticleTags);
$Article->bindModel(array('hasAndBelongsToMany' => array(
'Tag' => array('with' => 'TestPlugin.ArticlesTag')
)), false);
$this->assertTrue($Article->delete(1));
}
/**
* test deleteLinks with Multiple habtm associations
*