From efa9eaba4d37f54fc764debf71a85303b6a222d4 Mon Sep 17 00:00:00 2001 From: gwoo Date: Sun, 15 Oct 2006 07:10:32 +0000 Subject: [PATCH] fix for custom associations in bake 1.2 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3680 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/scripts/bake.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cake/scripts/bake.php b/cake/scripts/bake.php index d28327bcd..1eb80c85a 100644 --- a/cake/scripts/bake.php +++ b/cake/scripts/bake.php @@ -483,9 +483,9 @@ class Bake { //Look for belongsTo $i = 0; foreach($modelFields as $field) { - if($field['type'] == 'integer'){ - $possibleKeys[] = $field['name']; - } + $tm = $this->__modelName($otherTable); + $possibleKeys[$tm][] = $field['name']; + $offset = strpos($field['name'], '_id'); if($offset !== false) { $tmpModelName = $this->__modelNameFromKey($field['name']); @@ -502,9 +502,8 @@ class Bake { $modelFieldsTemp = $db->describe($tempOtherModel); $j = 0; foreach($modelFieldsTemp as $field) { - if($field['type'] == 'integer'){ - $possibleKeys[] = $field['name']; - } + $tm = $this->__modelName($otherTable); + $possibleKeys[$tm][] = $field['name']; if($field['name'] == $this->__modelKey($currentModelName)) { $tmpModelName = $this->__modelName($otherTable); $hasOne[$j]['alias'] = $tmpModelName; @@ -666,8 +665,8 @@ class Bake { $associationName = $this->getInput('What is the name of this association?'); $className = $this->getInput('What className will '.$associationName.' use?'); $this->stdout('A helpful List of possible keys'); - for ($i = 0; $i < count($possibleKeys); $i++) { - $this->stdout($i + 1 . ". " . $possibleKeys[$i]); + for ($i = 0; $i < count($possibleKeys[$className]); $i++) { + $this->stdout($i + 1 . ". " . $possibleKeys[$className][$i]); } $foreignKey = $this->getInput('What is the foreignKey? Choose a number or specify your own.', null, $this->__modelKey($associationName)); if (intval($foreignKey) > 0 && intval($foreignKey) <= $i ) {