views:

47

answers:

0

Hey

I have problem with the following Doctrine_RawSql:

public function getWithThreads($forum_id)
{


    $conn = Doctrine_Manager::connection();
    $q = new Doctrine_RawSql($conn);

    $q->select('{f.*},{t.*}, {p.id}, {p.last_post_date} ')
        ->from(sprintf("forum f LEFT JOIN thread t ON t.forum_id = f.id JOIN (SELECT MAX(p.created_at) AS last_post_date, p.id,p.thread_id, p.user_id AS last_post_user_id FROM post p GROUP BY p.thread_id) p ON p.thread_id = t.id WHERE t.forum_id = f.id AND  f.id = %d",$forum_id))
        ->addComponent('f','Forum f')     
        ->addComponent('t','f.Threads t')
        ->addComponent('p','t.Posts p')
        ->setHydrationMode(Doctrine::HYDRATE_RECORD);
     return   $q->execute();

}

This function should return forum with threads and date of last post for each thread. In controller:

public function executeShow(sfWebRequest $request)
{
   $this->forum = Doctrine::getTable('Forum')->getWithThreads($request->getParameter('forum_id'));
   $this->forward404Unless($this->forum);
}

And it works but... when I try to display content in this way:

<?php foreach($forum->getThreads() as $thread): ?>
    <tr>
       //some code
    </tr>
    <?php endforeach; ?>

I get this error:

Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'Doctrine_Collection::getCategory' was given in /home/symfony/1.4.6/lib/escaper/sfOutputEscaperObjectDecorator.class.php on line 64

I have checked how the results looks like and with normal Doctrine_Query:create() the output as array is:

sfOutputEscaperArrayDecorator Object
(
    [count:private] => 6
    [value:protected] => Array
        (
            [id] => 1
            [title] => f1
            [priority] => 1
            [description] => f1
            [category_id] => 1
            [Threads] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [title] => t1
                            [forum_id] => 1
                            [closed] => 
                            [created_at] => 2010-07-28 14:44:25
                            [updated_at] => 2010-07-28 14:44:25
                            [Forum] => 
                            [Posts] => Array
                                (
                                    [0] => Array
                                        (
                                            [id] => 1
                                            [thread_id] => 1
                                            [user_id] => 32
                                            [content] => pierwszy t1
                                            [created_at] => 2010-10-10 00:11:00
                                            [updated_at] => 2010-07-28 14:44:25
                                            [Thread] => 
                                        )

but with Doctrine_RawSql:

sfOutputEscaperArrayDecorator Object
(
    [count:private] => 1
    [value:protected] => Array
        (
            **[0] => Array**
                (
                    [id] => 1
                    [title] => f1
                    [priority] => 1
                    [description] => f1
                    [category_id] => 1
                    [Threads] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 3
                                    [title] => t3
                                    [forum_id] => 1
                                    [closed] => 
                                    [created_at] => 2010-07-28 14:44:25
                                    [updated_at] => 2010-07-28 14:44:25
                                    [Forum] => 
                                    [Posts] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [id] => 11
                                                    [thread_id] => 3
                                                    [user_id] => 33
                                                    [content] => pierwszy t3
                                                    [created_at] => 2010-07-25 00:11:00
                                                    [updated_at] => 2010-07-28 14:44:25
                                                    [Thread] => 
                                                )

As you can see, in a second case content form first query is covered with one additional "array". I realy don't know how to deal with this issue.

Thanks in advance