Symfony and Doctrine select query doesn't work properly

Discussion relating to version 1.3.x and 1.4.x

Symfony and Doctrine select query doesn't work properly

Postby trkich » Tue Dec 27, 2011 12:05 pm

I have M:M relation between video and playlist table (playlist_has_video)

For example if I add the same video 3 times in playlist and when i try to select videos from that playlist I get only one result (video), but I need to get 3 results (videos).

My query is:

Code: Select all
$q_videos = Doctrine_Query::create()
            ->select('V.*, PHV.*')
            ->distinct(FALSE)
            ->from('Video V')
            ->leftJoin('V.VideoSource VS')
            ->leftJoin('V.PlaylistHasVideo PHV')
            ->orderBy("PHV.position ASC")
            ->where('PHV.playlist_id = ? AND V.instance_id = ? AND VS.transcoded = ?', array($this->getObject()->getId(), sfContext::getInstance()->getUser()->getAttribute('instance_id'), 1));


I check query in log and its OK:

Code: Select all
SELECT v.id AS v__id, v.published AS v__published, v.share AS v__share, v.public AS v__public, v.title AS v__title, v.description AS v__description, v.thumbnail AS v__thumbnail, v.subtitle AS v__subtitle, v.created_at AS v__created_at, v.updated_at AS v__updated_at, v.views AS v__views, v.highlighted AS v__highlighted, v.created_by AS v__created_by, v.updated_by AS v__updated_by, v.instance_id AS v__instance_id, p.id AS p__id, p.playlist_id AS p__playlist_id, p.video_id AS p__video_id, p.position AS p__position FROM video v LEFT JOIN video_source v2 ON v.id = v2.video_id LEFT JOIN playlist_has_video p ON v.id = p.video_id WHERE (p.playlist_id = '1' AND v.instance_id = '1' AND v2.transcoded = '1') ORDER BY p.position ASC


When execute this query in phpMyAdmin it return me good results - 3 results (videos)

Doctrine Version: 1.2.3 Symfony Version: 1.4.8

Anyone can help me?
trkich
Junior Member
 
Posts: 6
Joined: Thu Oct 15, 2009 2:46 pm
Location: Mostar

Re: Symfony and Doctrine select query doesn't work properly

Postby kindrosker » Mon Jan 02, 2012 10:32 am

I think you have to group values by playlist_id
try to add
Code: Select all
->groupBy('PHV.playlist_id')
User avatar
kindrosker
Member
 
Posts: 59
Joined: Sat Jul 12, 2008 12:16 am
Location: Ukraine

Re: Symfony and Doctrine select query doesn't work properly

Postby trkich » Wed Jan 04, 2012 11:54 am

Hi, thanks for reply,
I try but i get the same results. Again query return me only one Video.

I think this is some "problem" with Doctrine object hydration...

When I use Doctrine::HYDRATE_ARRAY in execute, i get good results..
trkich
Junior Member
 
Posts: 6
Joined: Thu Oct 15, 2009 2:46 pm
Location: Mostar


Return to symfony 1.3 and 1.4

Who is online

Users browsing this forum: No registered users and 5 guests