| | 754 | $t->diag('groupBy()'); |
|---|
| | 755 | |
|---|
| | 756 | ArticlePeer::doDeleteAll(); |
|---|
| | 757 | CommentPeer::doDeleteAll(); |
|---|
| | 758 | |
|---|
| | 759 | $article1 = new Article(); |
|---|
| | 760 | $article1->setTitle('bbbbb'); |
|---|
| | 761 | $article1->setCategory($category1); |
|---|
| | 762 | $article1->save(); |
|---|
| | 763 | $author1 = new Author(); |
|---|
| | 764 | $author1->setName('John'); |
|---|
| | 765 | $author1->save(); |
|---|
| | 766 | $comment = new Comment(); |
|---|
| | 767 | $comment->setContent('foo'); |
|---|
| | 768 | $comment->setArticleId($article1->getId()); |
|---|
| | 769 | $comment->setAuthor($author1); |
|---|
| | 770 | $comment->save(); |
|---|
| | 771 | |
|---|
| | 772 | $finder = sfPropelFinder::from('Article')-> |
|---|
| | 773 | join('Comment')-> |
|---|
| | 774 | groupBy('Article.Id')-> |
|---|
| | 775 | withColumn('COUNT(comment.ID)', 'NbComments'); |
|---|
| | 776 | $article = $finder->findOne(); |
|---|
| | 777 | $t->is($finder->getLatestQuery(), 'SELECT article.ID, article.TITLE, article.CATEGORY_ID, COUNT(comment.ID) AS NbComments FROM article, comment WHERE article.ID=comment.ARTICLE_ID GROUP BY article.ID LIMIT 1', 'groupBy() accepts a column name and issues a GROUP BY clause'); |
|---|
| | 778 | |
|---|
| | 779 | $finder = sfPropelFinder::from('Article')-> |
|---|
| | 780 | join('Comment')-> |
|---|
| | 781 | withColumn('Article.Id', 'foo')-> |
|---|
| | 782 | groupBy('foo')-> |
|---|
| | 783 | withColumn('COUNT(comment.ID)', 'NbComments'); |
|---|
| | 784 | $article = $finder->findOne(); |
|---|
| | 785 | $t->is($finder->getLatestQuery(), 'SELECT article.ID, article.TITLE, article.CATEGORY_ID, article.ID AS foo, COUNT(comment.ID) AS NbComments FROM article, comment WHERE article.ID=comment.ARTICLE_ID GROUP BY foo LIMIT 1', 'groupBy() accepts a column alias and issues a GROUP BY clause'); |
|---|
| | 786 | |
|---|
| | 787 | $finder = sfPropelFinder::from('Article')-> |
|---|
| | 788 | join('Comment')-> |
|---|
| | 789 | groupByArticle_Id()-> |
|---|
| | 790 | withColumn('COUNT(comment.ID)', 'NbComments'); |
|---|
| | 791 | $article = $finder->findOne(); |
|---|
| | 792 | $t->is($finder->getLatestQuery(), 'SELECT article.ID, article.TITLE, article.CATEGORY_ID, COUNT(comment.ID) AS NbComments FROM article, comment WHERE article.ID=comment.ARTICLE_ID GROUP BY article.ID LIMIT 1', 'groupByXXX() accepts a column name and issues a GROUP BY clause'); |
|---|
| | 793 | |
|---|
| | 794 | $t->diag('groupByClass()'); |
|---|
| | 795 | |
|---|
| | 796 | ArticlePeer::doDeleteAll(); |
|---|
| | 797 | CommentPeer::doDeleteAll(); |
|---|
| | 798 | |
|---|
| | 799 | $article1 = new Article(); |
|---|
| | 800 | $article1->setTitle('bbbbb'); |
|---|
| | 801 | $article1->setCategory($category1); |
|---|
| | 802 | $article1->save(); |
|---|
| | 803 | $author1 = new Author(); |
|---|
| | 804 | $author1->setName('John'); |
|---|
| | 805 | $author1->save(); |
|---|
| | 806 | $comment = new Comment(); |
|---|
| | 807 | $comment->setContent('foo'); |
|---|
| | 808 | $comment->setArticleId($article1->getId()); |
|---|
| | 809 | $comment->setAuthor($author1); |
|---|
| | 810 | $comment->save(); |
|---|
| | 811 | |
|---|
| | 812 | $finder = sfPropelFinder::from('Article')-> |
|---|
| | 813 | join('Comment')-> |
|---|
| | 814 | groupByClass('Article')-> |
|---|
| | 815 | withColumn('COUNT(comment.ID)', 'NbComments'); |
|---|
| | 816 | $article = $finder->findOne(); |
|---|
| | 817 | $t->is($finder->getLatestQuery(), 'SELECT article.ID, article.TITLE, article.CATEGORY_ID, COUNT(comment.ID) AS NbComments FROM article, comment WHERE article.ID=comment.ARTICLE_ID GROUP BY article.ID,article.TITLE,article.CATEGORY_ID LIMIT 1', 'groupByClass() accepts a model class name and issues a GROUP BY clause on all columns'); |
|---|
| | 818 | |
|---|