Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default ORDER BY via the property Model::$order cause errors on some postgreSQL statements #5155

Closed
rbecheras opened this issue Nov 13, 2014 · 2 comments
Assignees
Milestone

Comments

@rbecheras
Copy link

Consider a model as following:

class Zone extends AppModel {

/**
 * $order is the default order for find queries
 *
 * @var string
 */
    public $order = 'reference ASC';
/**
 * Attached Behaviors
 * 
 * @var array
 */
    public $actsAs = array('Tree');

create a new "Zone" element from POST form like :

$this->Zone->save($this->request->data);

will cause a SQL query as the following :

SELECT MAX("Zone"."rght") AS "rght" 
FROM "mpdefault"."zones" AS "Zone" 
WHERE 1 = 1 AND "Zone"."id" <> 126 ORDER BY "reference" ASC LIMIT 1

MySQL will accept it but PostgreSQL will throw this error :

Error: SQLSTATE[42803]: Grouping error: 7 ERROR: column "Zone.reference" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: ...RE 1 = 1 AND "Zone"."id" <> 126 ORDER BY "reference... ^ 

The only way I found to run my application was to completely remove the property Zone::$order

@dereuromark dereuromark added this to the 2.5.7 milestone Nov 13, 2014
@markstory markstory self-assigned this Nov 14, 2014
markstory added a commit that referenced this issue Nov 14, 2014
Models can define default order conditions that will cause issues with
postgres. By setting order=>false on all the queries emitted by
TreeBehavior, we can avoid this issue and not have issues with models
that define a default ordering.

Refs #5155
@markstory
Copy link
Member

Closing as #5159 is open now.

@rbecheras
Copy link
Author

What a quick reaction ! Thanks @markstory !

markstory added a commit that referenced this issue Nov 14, 2014
Add order=>false to all treebehavior queries.

Refs #5155
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants