/**
* test a full example of using virtual fields
*
* @return void
*/
public function testVirtualFieldsFetch()
{
$this->loadFixtures('Article', 'Comment');
$Article = ClassRegistry::init('Article');
$Article->virtualFields = array('comment_count' => 'SELECT COUNT(*) FROM ' . $this->Dbo->fullTableName('comments') . ' WHERE Article.id = ' . $this->Dbo->fullTableName('comments') . '.article_id');
$conditions = array('comment_count >' => 2);
$query = 'SELECT ' . join(',', $this->Dbo->fields($Article, null, array('id', 'comment_count'))) . ' FROM ' . $this->Dbo->fullTableName($Article) . ' Article ' . $this->Dbo->conditions($conditions, true, true, $Article);
$result = $this->Dbo->fetchAll($query);
$expected = array(array('Article' => array('id' => 1, 'comment_count' => 4)));
$this->assertEquals($expected, $result);
}