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
This commit is contained in:
mark_story 2014-04-04 21:26:31 -04:00
parent c92769c980
commit b8e21c99ee

View file

@ -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(