Fixing issue with persistModels and plugin models, closes #192 and #198

This commit is contained in:
José Lorenzo Rodríguez 2010-01-18 13:05:30 -04:30
parent 8f2a4a1e0e
commit cb4a1f07e5
7 changed files with 83 additions and 7 deletions

View file

@ -667,6 +667,9 @@ class Model extends Overloadable {
} else {
$this->{$assoc} =& ClassRegistry::init($model);
}
if (strpos($className, '.') !== false) {
ClassRegistry::addObject($className, $this->{$assoc});
}
if ($assoc) {
$this->tableToModel[$this->{$assoc}->table] = $assoc;
}

View file

@ -275,7 +275,7 @@ class Object {
if (strpos($key, '_behavior') !== false) {
App::import('Behavior', Inflector::classify(substr($key, 0, -9)));
} else {
App::import('Model', Inflector::classify($key));
App::import('Model', Inflector::camelize($key));
}
unset ($value);
}

View file

@ -431,6 +431,7 @@ class ObjectTest extends CakeTestCase {
$this->assertFalse(class_exists('PersisterOneBehaviorBehavior'));
$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
$this->assertFalse(class_exists('TestPluginPersisterBehavior'));
$this->assertFalse(class_exists('TestPluginAuthors'));
$Controller = new RequestActionPersistentController();
$Controller->persistModel = true;
@ -439,13 +440,18 @@ class ObjectTest extends CakeTestCase {
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
$contents = str_replace('"PersisterOne"', '"PersisterTwo"', file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
$contents = str_replace('persister_one_', 'persister_two_', file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
$contents = file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
$contents = str_replace('"PersisterOne"', '"PersisterTwo"', $contents);
$contents = str_replace('persister_one', 'persister_two', $contents);
$contents = str_replace('test_plugin_comment', 'test_plugin_authors', $contents);
$result = file_put_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php', $contents);
$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
$this->assertTrue(class_exists('TestPluginPersisterOneBehavior'));
$this->assertTrue(class_exists('TestPluginComment'));
$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
$this->assertFalse(class_exists('TestPluginPersisterTwoBehavior'));
$this->assertFalse(class_exists('TestPluginAuthors'));
$Controller = new RequestActionPersistentController();
$Controller->persistModel = true;
@ -454,6 +460,7 @@ class ObjectTest extends CakeTestCase {
$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
$this->assertTrue(class_exists('PersisterTwoBehaviorBehavior'));
$this->assertTrue(class_exists('TestPluginPersisterTwoBehavior'));
$this->assertTrue(class_exists('TestPluginAuthors'));
@unlink(CACHE . 'persistent' . DS . 'persisterone.php');
@unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
@ -490,6 +497,8 @@ class ObjectTest extends CakeTestCase {
$this->assertEqual($keys, array(
'persister_one',
'comment',
'test_plugin_comment',
'test_plugin.test_plugin_comment',
'persister_one_behavior_behavior',
'test_plugin_persister_one_behavior',
'test_plugin.test_plugin_persister_one_behavior'
@ -504,6 +513,8 @@ class ObjectTest extends CakeTestCase {
$this->assertEqual($keys, array(
'persister_one',
'comment',
'test_plugin_comment',
'test_plugin.test_plugin_comment',
'persister_one_behavior_behavior',
'test_plugin_persister_one_behavior',
'test_plugin.test_plugin_persister_one_behavior',

View file

@ -28,8 +28,8 @@ class PersisterOne extends AppModel {
var $useTable = 'posts';
var $name = 'PersisterOne';
var $actsAs = array('PersisterOneBehavior','TestPlugin.TestPluginPersisterOne');
var $actsAs = array('PersisterOneBehavior', 'TestPlugin.TestPluginPersisterOne');
var $hasMany = array('Comment');
var $hasMany = array('Comment', 'TestPlugin.TestPluginComment');
}
?>

View file

@ -28,8 +28,8 @@ class PersisterTwo extends AppModel {
var $useTable = 'posts';
var $name = 'PersisterTwo';
var $actsAs = array('PersisterOneBehavior','TestPlugin.TestPluginPersisterOne');
var $actsAs = array('PersisterOneBehavior', 'TestPlugin.TestPluginPersisterOne');
var $hasMany = array('Comment');
var $hasMany = array('Comment', 'TestPlugin.TestPluginComment');
}
?>

View file

@ -0,0 +1,31 @@
<?php
/* SVN FILE: $Id$ */
/**
* Test App Comment Model
*
*
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2006-2008, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs.
* @since CakePHP v 1.2.0.7726
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class TestPluginAuthors extends TestPluginAppModel {
var $useTable = 'authors';
var $name = 'TestPluginAuthors';
}
?>

View file

@ -0,0 +1,31 @@
<?php
/* SVN FILE: $Id$ */
/**
* Test App Comment Model
*
*
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2006-2008, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs.
* @since CakePHP v 1.2.0.7726
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class TestPluginComment extends TestPluginAppModel {
var $useTable = 'comments';
var $name = 'TestPluginComment';
}
?>