$query = 'SELECT article.ID, article.TITLE, article.CATEGORY_ID FROM article WHERE (article.TITLE LIKE \'%foo%\' AND article.CATEGORY_ID=1)'; $articles = $finder->filter(array( 'Title' => '*foo*', 'CategoryId' => '1' ))->find(); $t->is($finder->getLatestQuery(), $query, 'filter() calls filterBy() on each condition'); $finder = new sfPropelFinder('Article'); $articles = $finder->filter(array( 'title' => '*foo*', 'category_id' => '1' ), true)->find(); $t->is($finder->getLatestQuery(), $query, 'filter() converts underscore column names to CamelCase when the second argument is true'); $finder = new sfPropelFinder('Article'); $c = $finder->filter(array( 'Title' => '*foo*', 'CategoryId' => '1' ), false, array('Title'))->getCriteria(); $expectedC = new Criteria(); $expectedC->add(ArticlePeer::TITLE, '%foo%', Criteria::LIKE); $t->ok($c->equals($expectedC), 'filter() ignores column names that are not part of the third argument if passed'); $called = false; class myArticleFinder extends DbFinder
$article3->save(); $finder = new sfPropelFinder('Article'); $article = $finder->findPk($article2->getId()); $t->is($article->getTitle(), 'foo2', 'findPk() returns the object with the primary key matching the argument'); $t->ok(!is_array($article), 'findPk() returns a single object when passed a single primary key'); $finder = new sfPropelFinder('Article'); $article = $finder->findPk(76543787654); $t->is($article, null, 'findPk() returns null if the primary key is not found'); $finder = new sfPropelFinder('Article'); $articles = $finder->findPk(array($article2->getId(), $article1->getId())); $t->ok(is_array($articles), 'findPk() returns an array of objects when passed an array of primary keys'); $t->is(count($articles), 2, 'findPk() returns the objects with the primary keys matching the arguments'); $article = $finder->with('Category')->findPk($article2->getId()); $t->cmp_ok(strpos($finder->getLatestQuery(), 'SELECT article.ID, article.TITLE, article.CATEGORY_ID, category.ID, category.NAME FROM article INNER JOIN category'), '===', 0, 'findPk() is compatible with with()'); ArticlePeer::doDeleteAll(); $article1 = new Article(); $article1->setTitle('foo'); $article1->setCulture('fr'); $article1->setContent('Bar'); $article1->save(); $articlei18n1 = $article1->getCurrentArticleI18n(); try { $articleI18n = sfPropelFinder::from('ArticleI18n')->findPk($articlei18n1->getId()); $t->fail('findPk() expects an array of values for objects with composite primary keys'); } catch(Exception $e)