Usage:
to add a field
$query->fields('created');
to add several fields
$query->fields(array('title','body','modified'));
to reset fields to none
$query->fields(false);
should be followed by a 2nd call to fields with required fields
public function testFields() { $query = new Query($this->_queryArr); $expected = array('id','author_id','title'); $result = $query->fields(); $this->assertEqual($expected, $result); $query->fields('content'); $expected = array('id','author_id','title','content'); $result = $query->fields(); $this->assertEqual($expected, $result); $query->fields(array('updated','created')); $expected = array('id','author_id','title','content','updated','created'); $result = $query->fields(); $this->assertEqual($expected, $result); $query->fields(false); $query->fields(array('id', 'title')); $expected = array('id','title'); $result = $query->fields(); $this->assertEqual($expected, $result); }
public function testFieldsWithArray() { $query = new Query(array('model' => 'lithium\\tests\\mocks\\data\\model\\MockQueryPost', 'type' => 'read', 'with' => 'MockQueryComment')); $query->fields(array('MockQueryPost', 'MockQueryPost' => array('id'))); $result = $query->fields(); $expected = array('MockQueryPost', 'MockQueryPost.id'); $this->assertEqual($expected, $result); $query->fields(false); $query->fields(array('MockQueryPost' => array('id'), 'title', 'MockQueryComment' => array('comment', 'title'), 'MockQueryComment')); $result = $query->fields(); $expected = array('MockQueryPost.id', 'title', 'MockQueryComment.comment', 'MockQueryComment.title', 'MockQueryComment'); $this->assertEqual($expected, $result); }