|
|
@@ -2110,10 +2110,42 @@ class Model extends Object {
|
|
|
$this->findQueryType = $type;
|
|
|
$this->id = $this->getID();
|
|
|
|
|
|
+ $query = $this->buildQuery($type, $query);
|
|
|
+ if (is_null($query)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ $results = $this->getDataSource()->read($this, $query);
|
|
|
+ $this->resetAssociations();
|
|
|
+
|
|
|
+ if ($query['callbacks'] === true || $query['callbacks'] === 'after') {
|
|
|
+ $results = $this->_filterResults($results);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->findQueryType = null;
|
|
|
+
|
|
|
+ if ($type === 'all') {
|
|
|
+ return $results;
|
|
|
+ } else {
|
|
|
+ if ($this->findMethods[$type] === true) {
|
|
|
+ return $this->{'_find' . ucfirst($type)}('after', $query, $results);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Builds the query array that is used by the data source to generate the query to fetch the data.
|
|
|
+ *
|
|
|
+ * @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
|
|
|
+ * @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
|
|
|
+ * @return array Query array or null if it could not be build for some reasons
|
|
|
+ * @see Model::find()
|
|
|
+ */
|
|
|
+ public function buildQuery($type = 'first', $query = array()) {
|
|
|
$query = array_merge(
|
|
|
array(
|
|
|
'conditions' => null, 'fields' => null, 'joins' => array(), 'limit' => null,
|
|
|
- 'offset' => null, 'order' => null, 'page' => 1, 'group' => null, 'callbacks' => true
|
|
|
+ 'offset' => null, 'order' => null, 'page' => 1, 'group' => null, 'callbacks' => true,
|
|
|
),
|
|
|
(array)$query
|
|
|
);
|
|
|
@@ -2155,23 +2187,8 @@ class Model extends Object {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- $results = $this->getDataSource()->read($this, $query);
|
|
|
- $this->resetAssociations();
|
|
|
-
|
|
|
- if ($query['callbacks'] === true || $query['callbacks'] === 'after') {
|
|
|
- $results = $this->_filterResults($results);
|
|
|
- }
|
|
|
-
|
|
|
- $this->findQueryType = null;
|
|
|
-
|
|
|
- if ($type === 'all') {
|
|
|
- return $results;
|
|
|
- } else {
|
|
|
- if ($this->findMethods[$type] === true) {
|
|
|
- return $this->{'_find' . ucfirst($type)}('after', $query, $results);
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ return $query;
|
|
|
}
|
|
|
|
|
|
/**
|