views:

18

answers:

1

The site is already built from years. I am doing some modifications to it. It has controllers "Posts" and "Topics". On the topics page all recent posts are displayed. So it is a simple find of posts from "Posts" table. The fetch is not all assiciated to topic as we are showing all "Posts" and not "Topic" specific "Posts". In Topics controller, App::import('Model', 'Post'); and $Posts = new Post; are added and I call the action "getDiscussions" from Model "Post". The problem is that though I am not using any left join with "Topics" and "Users" (which is one more model used to display user details with post), the query is adding Left joins with two tables and that is giving a wrong result.

Please help.

Many Thanks Yukti

A: 

I think it is better to try to find out why cake is doing these "joins", rather than performing yet another forced query, so you might want to look into your model associations to check dependancies. Also, you can set $this->Posts->recursive = -1; to make sure you don't import unwanted stuff.

In the end, I am not sure what query you are trying to perform, so I can't help you further. However, here is a sample of a query I have successfully used to perform a left join, as I've noticed that many examples I found while writing my own were bugged:

$user_record = $this->User->find('first', array(
        'conditions' => array('`Openidurl`.`openid`' => $openid),
        'joins' => array(
            array(
                'table' => 'openidurls',
                'alias' => 'Openidurl',
                'type' => 'LEFT',
                'foreignKey' => 'user_id',
                'conditions'=> array('`Openidurl`.`user_id` = `User`.`id`')
            )
        )
    )
);
Damien
Thanks Damien , you are right recursive and 'unbindModel' come to rescue. $this->Topic->unbindModel(array('hasMany'=>array('Post')));
yukti
Another issue with pagunation I am facing .. I am using functioin in model "Posts". This is to fetch some condition based records and display with pagination. The pagination is not working here , Is it essential that "pagination" should be used in controllers only ? Please suggest.
yukti
I am not familiar with the pagination helper yet, but I'd assume "yes". Don't hesitate to open a new question for your issue, it might attract more people. Also, if you are experiencing too many issues with your data fetch, I'm afraid you are doing it wrong with the model associations, which will only make it more difficult with time.
Damien