Fixing issues with models using default inflected tables instead of their actual tables when detecting associations. Fixes #315

This commit is contained in:
mark_story 2009-11-16 09:24:52 -05:00
parent ddb9f8924c
commit 89558dc4af

View file

@ -130,8 +130,11 @@ class ModelTask extends Shell {
* @param string $className Name of class you want model to be.
* @return object Model instance
*/
function &_getModelObject($className) {
$object = new Model(array('name' => $className, 'ds' => $this->connection));
function &_getModelObject($className, $table = null) {
if (!$table) {
$table = Inflector::tableize($className);
}
$object =& new Model(array('name' => $className, 'table' => $table, 'ds' => $this->connection));
return $object;
}
@ -517,7 +520,7 @@ class ModelTask extends Shell {
function findHasOneAndMany(&$model, $associations) {
$foreignKey = $this->_modelKey($model->name);
foreach ($this->__tables as $otherTable) {
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable));
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
$modelFieldsTemp = $tempOtherModel->schema();
$pattern = '/_' . preg_quote($model->table, '/') . '|' . preg_quote($model->table, '/') . '_/';
@ -560,7 +563,7 @@ class ModelTask extends Shell {
function findHasAndBelongsToMany(&$model, $associations) {
$foreignKey = $this->_modelKey($model->name);
foreach ($this->__tables as $otherTable) {
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable));
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
$modelFieldsTemp = $tempOtherModel->schema();
$offset = strpos($otherTable, $model->table . '_');