I finally managed to get this working using a model bind. It's a bit
messy and doesn't really make a whole lot of sense to me just yet. I
was basically changing things and looking at the sql. For anyone
looking for this type of functionality, I achieved it using this in my
controller.

<?php
function index() {
        $this->checkRole(array(1,3));

        $this->Link->recursive = 1;

        $this->Link->bindModel(
                array('belongsTo' => array(
                                        'CategoriesLink' => array(
                                                        'className' => 
'CategoriesLink',
                                                        'foreignKey' => 'id',
                                        )
                        )),
                array('belongsTo' => array(
                                        'Category' => array(
                                                        'className' => 
'Category',
                                                        'foreignKey' => 
'categories_link_id',
                                        )
                        ))
        );

        if(isset($this->params['named']['category'])){
                $data = $this->paginate('Link', 
array('CategoriesLink.category_id'=>
$this->params['named']['category']));
        } else {
                $data = $this->paginate('Link', array('Link.status_id'=>'1'));
        }

        die(pr($data));

        $this->set('links', $data_mod);

        $categories = $this->Link->Category->find('list');
        $this->set(compact('categories'));
}
?>

On Aug 20, 12:34 pm, David Yell <[EMAIL PROTECTED]> wrote:
> Does this mean that 1.2 still can't filter a result set by a related
> model over habtm?
>
> I've been trying to filter my Links by Category to no avail today.
>
> Link habtm Category
> Category habtm Link
>
> $this->set('links', $this->paginate('Link', array('Category.id'=>$this-
>
> >data['Link']['category_id'])));
>
> Which fails because CakePHP won't join the related model in the query.
> Will I be reduced to creating a Model for the join CategoriesLink and
> then writing my own query to grab data from it? It seems determined to
> do two separate queries.
>
> The only other way I could think of, which I haven't tried yet, was to
> use /category/5/$link_id which might work, but I assumed would suffer
> the same fate in the sql of missing a join. Or should I be making an
> on-the-fly bind using a belongsTo association to force the join, which
> would then pickup my conditions?
>
> I have read the CakeBaker article (http://cakebaker.42dh.com/
> 2007/10/17/pagination-of-data-from-a-habtm-relationship/), but that
> looks to be for 1.1 as my existing habtm works for reading and saving,
> but not for when you want to adjust the resultset using a field from
> the related model.
>
> Idea's or links would be appreciated!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to