Skip to content

Commit

Permalink
Don't treat tables that substring match as associations
Browse files Browse the repository at this point in the history
The table structure of:

- packages
- userpackages
- georegions
- userpackages_georegions

Should not create a habtm between packages & georegions.

Fixes #3532
  • Loading branch information
markstory committed Jan 15, 2013
1 parent a1035f7 commit eff4004
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Console/Command/Task/ModelTask.php
Expand Up @@ -627,7 +627,7 @@ public function findHasAndBelongsToMany(Model $model, $associations) {
$offset = strpos($otherTable, $model->table . '_');
$otherOffset = strpos($otherTable, '_' . $model->table);

if ($offset !== false) {
if ($offset === 0) {
$offset = strlen($model->table . '_');
$habtmName = $this->_modelName(substr($otherTable, $offset));
$associations['hasAndBelongsToMany'][] = array(
Expand All @@ -637,7 +637,7 @@ public function findHasAndBelongsToMany(Model $model, $associations) {
'associationForeignKey' => $this->_modelKey($habtmName),
'joinTable' => $otherTable
);
} elseif ($otherOffset !== false) {
} elseif ($otherOffset === 0) {
$habtmName = $this->_modelName(substr($otherTable, 0, $otherOffset));
$associations['hasAndBelongsToMany'][] = array(
'alias' => $habtmName,
Expand Down

0 comments on commit eff4004

Please sign in to comment.