orderBy() public method

Sets the fields to order the results by. They should be in the the format 'fieldname ASC|DESC'. e.g 'dateAdded DESC'.
public orderBy ( mixed $fields ) : Query
$fields mixed An array comprising strings in the above format (or a single string)
return Query The same instance of this class.
示例#1
0
 public function testOrdering()
 {
     $path = __DIR__ . '/fixtures/datastore/querytest';
     $config = new Config($path . '/');
     $repo = new Repository('countries', $config);
     $query = new Query($repo);
     $query->orderBy('capital DESC');
     $result = $query->execute();
     $this->assertEquals('Croatia', $result->first()->id);
     $this->assertEquals('Heard Island and McDonald Islands', $result[$result->count() - 1]->id);
 }
示例#2
0
 public function testOrderBy()
 {
     $path = __DIR__ . '/fixtures/datastore/querytest';
     $config = new Config($path . '/');
     $repo = new Repository('countries', $config);
     $query = new Query($repo);
     $query->orderBy('age ASC');
     $this->assertAttributeEquals(array('age ASC'), 'orderBy', $query);
     $query->orderBy(array('surname DESC', 'age DESC'));
     $this->assertAttributeEquals(array('surname DESC', 'age DESC'), 'orderBy', $query);
 }