From eff4004261a2bd05e4df54ee2af057c680ff50fc Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 14 Jan 2013 20:39:01 -0500 Subject: [PATCH] Don't treat tables that substring match as associations The table structure of: - packages - userpackages - georegions - userpackages_georegions Should not create a habtm between packages & georegions. Fixes #3532 --- lib/Cake/Console/Command/Task/ModelTask.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index df2725d1f15..be90d2168c3 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -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( @@ -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,