Development

#4392 ([sfSimpleBlogPlugin] Fails retrieving de list of posts)

You must first sign up to be able to contribute.

Ticket #4392 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

[sfSimpleBlogPlugin] Fails retrieving de list of posts

Reported by: 3mlabs Assigned to: francois
Priority: minor Milestone:
Component: sfSimpleBlogPlugin Version: 1.0.17
Keywords: Cc:
Qualification: Unreviewed

Description

I realize a clean installation sfSimpleBlogPlugin under symfony 1.0.17. There is a problem in query for the post count that runs on the action sfSimpleBlogPostAdmin / list:

$this->finder->withNbComments()

adds to the finder

leftJoin ( 'sfSimpleBlogComment c') ->
withColumn ( 'COUNT (sfSimpleBlogComment.Id)', 'NbComments') ->
where ( 'c.IsModerated', false) ->
groupBy ( 'c.SfBlogPostId');

that is fine to bring posts with the number of comments, but always gives 0 if you want to count the number of posts (sfPropelFinderPager->init() or sfDoctrineFinderPager-> init()) because the restriction

where( 'c.IsModerated' , False)

is maintained. I think this could be solved adding a method setCountPager (equivalent to setPeerCountMethod) to sfPropelFinderPager or sfDoctrineFinderPager to add a custom finder for de count query.

Change History

09/17/08 10:37:23 changed by francois

  • owner changed from francois to 3mlabs.

Not sure I get you. The SQL query that is executed for the count (MySQL) looks like:

SELECT COUNT(sf_blog_post.ID) 
FROM sf_blog_post 
LEFT JOIN sf_guard_user ON (sf_blog_post.AUTHOR_ID=sf_guard_user.ID) 
LEFT JOIN sf_blog_comment ON (sf_blog_post.ID=sf_blog_comment.SF_BLOG_POST_ID) 
WHERE sf_blog_comment.IS_MODERATED=0

This query looks OK and works fine on my side (it is all LEFT JOINs). What gives 0 exactly ? What query would you expect? Can you provide some test data to show the problem?

09/17/08 14:59:13 changed by 3mlabs

Hi, that query always returns 0 if the post has no comments (because sf_blog_comment.IS_MODERATED is NULL), wich prevents all newly created posts being listed in the admin (and consequently prevents publish/unpublish them). For me the expected query is

SELECT COUNT(sf_blog_post.ID) 
FROM sf_blog_post

But Maybe i miss something...

Note: I meant setCountFinder when wrote setCountPager

09/17/08 15:09:48 changed by francois

  • owner changed from 3mlabs to francois.

ah, I think I get the idea. In fact, the generated SQL should be

SELECT COUNT(sf_blog_post.ID) 
FROM sf_blog_post 
LEFT JOIN sf_guard_user ON (sf_blog_post.AUTHOR_ID=sf_guard_user.ID) 
LEFT JOIN sf_blog_comment ON (sf_blog_post.ID=sf_blog_comment.SF_BLOG_POST_ID AND sf_blog_comment.IS_MODERATED=0) 

But then I need a way to add multiple JOIN conditions to Propel, and this won't be possible till 1.4... So I'll think about a workaround.

09/17/08 15:26:57 changed by francois

  • status changed from new to closed.
  • resolution set to fixed.

(In [11607]) sfSimpleBlogPlugin Fixed missing posts in admin (closes #4392)

09/17/08 15:27:48 changed by francois

The fix increases the number of queries for now, I'll find a way to reoptimize it later.