Permalink
Browse files

Fixing issues with models using default inflected tables instead of t…

…heir actual tables when detecting associations. Fixes #315
  • Loading branch information...
1 parent ddb9f89 commit 89558dc4af33d9b1d7668d05adedc182f524ad60 @markstory markstory committed Nov 16, 2009
Showing with 7 additions and 4 deletions.
  1. +7 −4 cake/console/libs/tasks/model.php
View
11 cake/console/libs/tasks/model.php
@@ -130,8 +130,11 @@ function all() {
* @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 @@ function findBelongsTo(&$model, $associations) {
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 @@ function findHasOneAndMany(&$model, $associations) {
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 . '_');

0 comments on commit 89558dc

Please sign in to comment.