Browse Source

Only count `_id` if it is the last 3 characters in the field name.

This prevents issues when baking models for tables containing `_id`.

Fixes #3230
mark_story 12 years ago
parent
commit
b8e21c99ee
1 changed files with 1 additions and 1 deletions
  1. 1 1
      lib/Cake/Console/Command/Task/ModelTask.php

+ 1 - 1
lib/Cake/Console/Command/Task/ModelTask.php

@@ -572,7 +572,7 @@ class ModelTask extends BakeTask {
 	public function findBelongsTo(Model $model, $associations) {
 		$fieldNames = array_keys($model->schema(true));
 		foreach ($fieldNames as $fieldName) {
-			$offset = strpos($fieldName, '_id');
+			$offset = substr($fieldName, -3) === '_id';
 			if ($fieldName != $model->primaryKey && $fieldName !== 'parent_id' && $offset !== false) {
 				$tmpModelName = $this->_modelNameFromKey($fieldName);
 				$associations['belongsTo'][] = array(