Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allowing vritual fields to work whether specified with a model alias or

not. by concequence allows find('list', array('fields' => array('id',
'virtual'))) to work
  • Loading branch information...
commit 7943f3d1685c787a60a2c478125aa700e3e9ad24 1 parent d60a66f
Andy Dawson AD7six authored markstory committed
Showing with 16 additions and 6 deletions.
  1. +16 −6 cake/libs/model/datasources/dbo_source.php
22 cake/libs/model/datasources/dbo_source.php
View
@@ -106,7 +106,7 @@ class DboSource extends DataSource {
/**
* Constructor
- *
+ *
* @param array $config Array of configuration information for the Datasource.
* @param boolean $autoConnect Whether or not the datasource should automatically connect.
* @access public
@@ -668,7 +668,7 @@ function fullTableName($model, $quote = true) {
* Creates new records in the database.
*
* @param Model $model Model object that the record is for.
- * @param array $fields An array of field names to insert. If null, $model->data will be
+ * @param array $fields An array of field names to insert. If null, $model->data will be
* used to generate field names.
* @param array $values An array of values with keys matching the fields. If null, $model->data will
* be used to generate values.
@@ -853,7 +853,7 @@ function __filterResults(&$results, &$model, $filtered = array()) {
* Queries associations. Used to fetch results on recursive models.
*
* @param Model $model Primary Model object
- * @param Model $linkModel Linked model that
+ * @param Model $linkModel Linked model that
* @param string $type Association type, one of the model association types ie. hasMany
* @param unknown_type $association
* @param unknown_type $assocData
@@ -1840,7 +1840,7 @@ function __scrubQueryData($data) {
* @param mixed $fields virtual fields to be used on query
* @return array
*/
- function _constructVirtualFields(&$model,$alias,$fields) {
+ function _constructVirtualFields(&$model, $alias, $fields) {
$virtual = array();
foreach ($fields as $field) {
$virtualField = $this->name("{$alias}__{$field}");
@@ -1876,10 +1876,20 @@ function fields(&$model, $alias = null, $fields = array(), $quote = true) {
return $fields;
}
$virtual = array();
- if ($model->getVirtualField()) {
- $keys = array_keys($model->getVirtualField());
+ $virtualFields = $model->getVirtualField();
+ if ($virtualFields) {
+ $keys = array_keys($virtualFields);
+ foreach($keys as $field) {
+ $keys[] = $model->alias . '.' . $field;
+ }
$virtual = ($allFields) ? $keys : array_intersect($keys, $fields);
}
+ foreach($virtual as &$field) {
+ if (strpos($field, '.')) {
+ $field = str_replace($model->alias . '.', '', $field);
+ $fields = array_diff($fields, array($model->alias . '.' . $field));
+ }
+ }
$count = count($fields);
if ($count >= 1 && !in_array($fields[0], array('*', 'COUNT(*)'))) {
Please sign in to comment.
Something went wrong with that request. Please try again.