public function testOneToMany() { $opts = array('conditions' => array('Galleries.id' => $this->gallery['id'])); $query = new Query($opts + array('type' => 'read', 'model' => 'lithium\\tests\\mocks\\data\\source\\Galleries', 'source' => 'galleries', 'alias' => 'Galleries', 'with' => array('Images'))); $galleries = $this->db->read($query)->data(); foreach ($galleries as $key => $gallery) { $expect = $this->gallery + array('images' => $this->images); $this->assertEqual($expect, $gallery); } $gallery = Galleries::find('first', $opts + array('with' => 'Images'))->data(); $expect = $this->gallery + array('images' => $this->images); $this->assertEqual($expect, $gallery); }
public function testGroup() { $this->_createGalleriesWithImages(); $galleries = Galleries::find('all', array('fields' => array(array('count(Images.id) AS count')), 'with' => 'Images', 'group' => array('Galleries.id'), 'order' => array('Galleries.id' => 'ASC'))); $this->assertEqual(2, count($galleries)); $expected = array(3, 2); foreach ($galleries as $gallery) { $this->assertEqual(current($expected), $gallery->count); next($expected); } }