Changed how fields are handled, so that they are all included by default and the user is not forced to specify them. This works with paginate, but the additional fields are requested in the count query. Would like to resolve this, but it doesn't seem to be confusing paginate.

git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@46 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-05-31 18:27:21 +00:00
parent 387c1ae87b
commit 6bf06a3a3c

View File

@@ -42,9 +42,16 @@ class LinkableBehavior extends ModelBehavior {
protected $_defaults = array('type' => 'LEFT');
public function beforeFind(&$Model, $query) {
//pr("Linkable::beforeFind() begin"); pr($query);
if (isset($query[$this->_key])) {
$optionsDefaults = $this->_defaults + array('reference' => $Model->alias, $this->_key => array());
$optionsKeys = $this->_options + array($this->_key => true);
if (!isset($query['fields']) || $query['fields'] === true) {
//$query['fields'] = array_keys($Model->_schema);
$query['fields'] = $Model->getDataSource()->fields($Model);
} elseif (!is_array($query['fields'])) {
$query['fields'] = array($query['fields']);
}
$query = am(array('joins' => array()), $query, array('recursive' => -1));
$iterators[] = $query[$this->_key];
$cont = 0;
@@ -125,16 +132,16 @@ class LinkableBehavior extends ModelBehavior {
if (empty($options['table'])) {
$options['table'] = $db->fullTableName($_Model, true);
}
if (!empty($options['fields'])) {
if ($options['fields'] === true && !empty($association['fields'])) {
$options['fields'] = $db->fields($_Model, null, $association['fields']);
} elseif ($options['fields'] === true) {
$options['fields'] = $db->fields($_Model);
} else {
$options['fields'] = $db->fields($_Model, null, $options['fields']);
}
$query['fields'] = array_merge($query['fields'], $options['fields']);
}
if (!isset($options['fields']) || !is_array($options['fields']))
$options['fields'] = $db->fields($_Model);
elseif (!empty($options['fields']))
$options['fields'] = $db->fields($_Model, null, $options['fields']);
$query['fields'] = array_merge($query['fields'], $options['fields'],
(empty($association['fields'])
? array() : $db->fields($_Model, null, $association['fields'])));
$options[$this->_key] = am($options[$this->_key], array_diff_key($options, $optionsKeys));
$options = array_intersect_key($options, $optionsKeys);
@@ -147,6 +154,7 @@ class LinkableBehavior extends ModelBehavior {
$notDone = isset($iterators[$cont]);
} while ($notDone);
}
//pr("Linkable::beforeFind() end"); pr($query);
return $query;
}
}