Skip to content
Browse files

moving order for finds from constructor to beforeFind

  • Loading branch information...
1 parent 2969a8f commit c12c853f1027894733a0893f35b81348533ddf98 @ceeram ceeram committed
Showing with 20 additions and 10 deletions.
  1. +20 −10 lib/Cake/TestSuite/Fixture/CakeTestModel.php
View
30 lib/Cake/TestSuite/Fixture/CakeTestModel.php
@@ -29,21 +29,31 @@ class CakeTestModel extends Model {
public $cacheSources = false;
/**
- * Constructor, sets default order for the model to avoid failing tests caused by
+ * Sets default order for the model to avoid failing tests caused by
* incorrect order when no order has been defined in the finds.
* Postgres can return the results in any order it considers appropriate if none is specified
*
- * @param mixed $id Set this ID for this model on startup, can also be an array of options, see Model::__construct().
- * @param string $table Name of database table to use.
- * @param string $ds DataSource connection name.
+ * @param array $queryData
+ * @return array $queryData
*/
- function __construct($id = false, $table = null, $ds = null) {
- parent::__construct($id, $table, $ds);
- if ($this->useTable && $this->primaryKey && $this->schema($this->primaryKey)) {
- $this->order = array($this->alias . '.' . $this->primaryKey => 'ASC');
- $this->_schema = null;
+ public function beforeFind($queryData) {
+ $pk = $this->primaryKey;
+ $aliasedPk = $this->alias . '.' . $this->primaryKey;
+ switch(true) {
+ case !$pk:
+ case !$this->useTable:
+ case !$this->schema('id'):
+ case !empty($queryData['order'][0]):
+ case !empty($queryData['group']):
+ case
+ (is_string($queryData['fields']) && !($queryData['fields'] == $pk || $queryData['fields'] == $aliasedPk)) ||
+ (is_array($queryData['fields']) && !(array_key_exists($pk, $queryData['fields']) || array_key_exists($aliasedPk, $queryData['fields']))):
+ break;
+ default:
+ $queryData['order'] = array($this->alias . '.' . $this->primaryKey => 'ASC');
+ break;
}
- $this->_sourceConfigured = false;
+ return $queryData;
}
}

0 comments on commit c12c853

Please sign in to comment.
Something went wrong with that request. Please try again.