Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed the @fixme. Aliased models now have the Alias in fields

  • Loading branch information...
commit fbfe43ab26c7efab42493d25a1333370406dd576 1 parent b1b9b29
@ProLoser authored
View
24 Model/Behavior/LinkableBehavior.php
@@ -156,12 +156,7 @@ public function beforeFind(Model $Model, $query) {
$options['fields'] = $db->fields($_Model);
} else {
$options['fields'] = $db->fields($_Model, null, $options['fields']);
- }
-
- if (is_array($query['fields']))
- $query['fields'] = array_merge($query['fields'], $options['fields']);
- else
- $query['fields'] = array_merge($db->fields($Model), $options['fields']);
+ }
}
else if (!isset($options['fields']) || (isset($options['fields']) && !is_array($options['fields'])))
{
@@ -170,13 +165,16 @@ public function beforeFind(Model $Model, $query) {
} else {
$options['fields'] = $db->fields($_Model);
}
-
- if (is_array($query['fields'])) {
- $query['fields'] = array_merge($query['fields'], $options['fields']);
- } else {
- // If user didn't specify any fields then select all fields by default (just as find would)
- $query['fields'] = array_merge($db->fields($Model), $options['fields']);
- }
+ }
+
+ if (!empty($options['class']) && $options['class'] !== $alias) {
+ $options['fields'] = str_replace($options['class'], $alias, $options['fields']);
+ }
+ if (is_array($query['fields'])) {
+ $query['fields'] = array_merge($query['fields'], $options['fields']);
+ } else {
+ // If user didn't specify any fields then select all fields by default (just as find would)
+ $query['fields'] = array_merge($db->fields($Model), $options['fields']);
}
}
View
2  Test/Case/Model/Behavior/LinkableBehaviorTest.php
@@ -225,7 +225,7 @@ public function testComplexAssociations()
'class' => 'Tag',
'conditions' => array('exactly' => 'PostsTag.post_id = Post.id'),
'fields' => array(
- 'MainTag.name' // @fixme Wants to use class name (Tag) instead of alias (MainTag)
+ 'MainTag.name'
)
)
)
Please sign in to comment.
Something went wrong with that request. Please try again.