|
@@ -408,12 +408,13 @@ class MyModel extends Model {
|
|
|
* @param string $type The type o the query ('count'/'all'/'first' - first only works with some mysql versions)
|
|
* @param string $type The type o the query ('count'/'all'/'first' - first only works with some mysql versions)
|
|
|
* @param array $options The options array
|
|
* @param array $options The options array
|
|
|
* @param string $alias You can use this intead of $options['alias'] if you want
|
|
* @param string $alias You can use this intead of $options['alias'] if you want
|
|
|
|
|
+ * @param bool $parenthesise Add parenthesis before and after
|
|
|
* @return string $result sql snippet of the query to run
|
|
* @return string $result sql snippet of the query to run
|
|
|
* @modified Mark Scherer (cake2.x ready and improvements)
|
|
* @modified Mark Scherer (cake2.x ready and improvements)
|
|
|
* @link http://bakery.cakephp.org/articles/lucaswxp/2011/02/11/easy_and_simple_subquery_cakephp
|
|
* @link http://bakery.cakephp.org/articles/lucaswxp/2011/02/11/easy_and_simple_subquery_cakephp
|
|
|
* 2011-07-05 ms
|
|
* 2011-07-05 ms
|
|
|
*/
|
|
*/
|
|
|
- public function subquery($type, $options = array(), $alias = null) {
|
|
|
|
|
|
|
+ public function subquery($type, $options = array(), $alias = null, $parenthesise = true) {
|
|
|
if ($alias === null) {
|
|
if ($alias === null) {
|
|
|
$alias = 'Sub' . $this->alias . '';
|
|
$alias = 'Sub' . $this->alias . '';
|
|
|
}
|
|
}
|
|
@@ -443,7 +444,10 @@ class MyModel extends Model {
|
|
|
'group' => null
|
|
'group' => null
|
|
|
);
|
|
);
|
|
|
$params = array_merge($default, $options);
|
|
$params = array_merge($default, $options);
|
|
|
- $subQuery = '(' . trim($dbo->buildStatement($params, $this)) . ')';
|
|
|
|
|
|
|
+ $subQuery = trim($dbo->buildStatement($params, $this));
|
|
|
|
|
+ if ($parenthesise) {
|
|
|
|
|
+ $subQuery = '(' . $subQuery . ')';
|
|
|
|
|
+ }
|
|
|
return $subQuery;
|
|
return $subQuery;
|
|
|
}
|
|
}
|
|
|
|
|
|