From ce252f2e708f91bd8cf6c08ee95eef49b1134aee Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 31 May 2009 18:27:21 +0000 Subject: [PATCH] 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/site@46 97e9348a-65ac-dc4b-aefc-98561f571b83 --- models/behaviors/linkable.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/models/behaviors/linkable.php b/models/behaviors/linkable.php index 32b28bb..428fc9b 100644 --- a/models/behaviors/linkable.php +++ b/models/behaviors/linkable.php @@ -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; } } \ No newline at end of file