public function testWithAssociation() {
$model = $this->_model;
$model::bind('hasMany', 'MockQueryComment', array(
'class' => 'lithium\tests\mocks\data\model\MockQueryComment'
));
$query = new Query(compact('model') + array('with' => 'MockQueryComment'));
$export = $query->export(new MockDatabase());
$expected = array('MockQueryComment' => array(
'type' => 'hasMany',
'model' => 'lithium\tests\mocks\data\model\MockQueryComment',
'fieldName' => 'mock_query_comments'
));
$keyExists = isset($export['relationships']);
$this->assertTrue($keyExists);
$this->skipIf(!$keyExists);
$this->assertEqual($expected, $export['relationships']);
$query = new Query(compact('model') + array(
'type' => 'read',
'with' => 'MockQueryComment',
'limit' => 3,
'order' => 'author_id ASC',
'group' => 'author_id'
));
$expected = 'SELECT * FROM {foo} AS {MockQueryPost} LEFT JOIN AS ';
$expected .= '{MockQueryComment} ON {MockQueryPost}.{id} = {MockQueryComment}';
$expected .= '.{mock_query_post_id} GROUP BY author_id ORDER BY author_id ASC ';
$expected .= 'LIMIT 3;';
$this->assertEqual($expected, $this->db->renderCommand($query));
}