コード例 #1
0
{
  $finder->with('DCategory')->find();
  $t->pass('Relations lookup work also on finder children objects');
}
catch (Exception $e)
{
  $t->fail('Relations lookup work also on finder children objects');
}

$t->diag('sfDoctrineFinder::with() and left joins');

Doctrine_Query::create()->delete()->from('DComment')->execute();
Doctrine_Query::create()->delete()->from('DArticle')->execute();
Doctrine_Query::create()->delete()->from('DCategory')->execute();

$category1 = new DCategory();
$category1->setName('cat1');
$category1->save();
$article1 = new DArticle();
$article1->setTitle('aaa');
$article1->setCategory($category1);
$article1->save();
$article2 = new DArticle();
$article2->setTitle('bbb');
$article2->save();

$article = sfDoctrineFinder::from('DArticle')->leftJoin('DCategory')->with('DCategory')->findLast();
$category = $article->getCategory();
if (is_object($category))
{
  $t->isa_ok($article->getCategory(), 'Doctrine_Null', 'In a left join using with(), empty related objects are not hydrated');
コード例 #2
0
$article2->save();
$finder = sfDoctrineFinder::from('DArticle');
$nbArticles1 = $finder->where('Title', 'aaaaa')->count();
$nbArticles2 = $finder->count();
$t->isnt($nbArticles1, $nbArticles2, 'By default, the query is reinitialized after a termination method');
$finder = sfDoctrineFinder::from('DArticle')->keepQuery();
$nbArticles1 = $finder->where('Title', 'aaaaa')->count();
$nbArticles2 = $finder->count();
$t->is($nbArticles1, $nbArticles2, 'Using keepQuery() keeps the query between two termination methods');
$t->diag('relatedTo()');
Doctrine_Query::create()->delete()->from('DArticle')->execute();
Doctrine_Query::create()->delete()->from('DCategory')->execute();
$category1 = new DCategory();
$category1->setName('cat1');
$category1->save();
$category2 = new DCategory();
$category2->setName('cat2');
$category2->save();
$article1 = new DArticle();
$article1->setTitle('aaaaa');
$article1->setCategory($category1);
$article1->save();
$article2 = new DArticle();
$article2->setTitle('bbbbb');
$article2->setCategory($category1);
$article2->save();
$article3 = new DArticle();
$article3->setTitle('ccccc');
$article3->setCategory($category2);
$article3->save();
$articles = sfDoctrineFinder::from('DArticle')->relatedTo($category1)->find();