#1635: Query work in mysql, not in postgresql
------------------------------+---------------------------------------------
  Reporter:  sikkle           |       Owner:  romanb               
      Type:  defect           |      Status:  closed               
  Priority:  minor            |   Milestone:  Unknown              
 Component:  Query/Hydration  |     Version:  1.0.3                
Resolution:  fixed            |    Keywords:  postgresql query     
  Has_test:  0                |    Mystatus:  Pending Core Response
 Has_patch:  1                |  
------------------------------+---------------------------------------------
Changes (by sikkle):

  * status:  new => closed
  * has_patch:  0 => 1
  * resolution:  => fixed

Old description:

> That query work into mysql, but not into postgresql.
>
> error //
>
> SQLSTATE[42803]: Grouping error: 7 ERROR: column "b.title" must appear in
> the GROUP BY clause or be used in an aggregate function
>

> action//
>
>   public function executeIndex($request)
>   {
>     $this->posts = Doctrine::getTable('BlogPost')->getAll();[[BR]]
>
>   }
>
> model //
>
>   public function getAll()
>   {
>     return Doctrine_Query::create()->[[BR]]
>
>       select('p.title, p.slug, p.body, p.author, p.created_at,
> count(c.id) numcomments')->
>       from('BlogPost p, p.BlogComment c')->
>       orderBy('p.created_at DESC')->
>       groupBy('p.id')->
>       execute();
>   }
>
> Schema //
>
> BlogPost:[[BR]]
>   actAs:[[BR]]
>     Sluggable:[[BR]]
>       fields:       [title][[BR]]
>     Timestampable:[[BR]]
>   columns:[[BR]]
>     title:          string(255)[[BR]]
>     body:           clob[[BR]]
>     author:         string(255)[[BR]]
>
> BlogComment:[[BR]]
>   actAs:            [Timestampable][[BR]]
>   columns:[[BR]]
>     blog_post_id:   integer[[BR]]
>     author:         string(255)[[BR]]
>     email:          string(255)[[BR]]
>     content:        clob[[BR]]
>   relations:[[BR]]
>     BlogPost:[[BR]]
>       class:        BlogPost[[BR]]
>       local:        blog_post_id[[BR]]
>       foreign:      id[[BR]]
>       foreignType:  many[[BR]]
>       type:         one[[BR]]

New description:

 public function getAll()
   {
     return Doctrine_Query::create()
       ->select('p.id, p.title, p.slug, p.body, p.author, p.created_at,
 count(c.id) numcomments')
       ->from('BlogPost p, p.BlogComment c')
       ->orderBy('p.created_at DESC')
       ->groupBy('p.id, p.title, p.slug, p.body, p.author, p.created_at')
       ->execute();

   }


 So it's postgresql specific, that will work.

 thanks!

-- 
Ticket URL: <http://trac.doctrine-project.org/ticket/1635#comment:2>
Doctrine <http://www.phpdoctrine.org>
PHP Doctrine Object Relational Mapper
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"doctrine-svn" group.
 To post to this group, send email to [email protected]
 To unsubscribe from this group, send email to [EMAIL PROTECTED]
 For more options, visit this group at 
http://groups.google.co.uk/group/doctrine-svn?hl=en-GB
-~----------~----~----~----~------~----~------~--~---

Reply via email to