On Jun 21, 6:06 pm, Nasko <[EMAIL PROTECTED]> wrote:
> Unfortunately, defining the fake model association in the Bookmarks
> model caused the normal $this->Bookmark->findAll() requests in other
> actions to return multiple records for each bookmark :(

As advised by AD7six on IRC I've reworked the association using
bindModel() before the pagination->init() method call and after it.
I've removed the hasOne association from my Bookmark model definition.

I've followed Adam's example above:

# bookmark.php
class Bookmark extends AppModel
{
    var $name = 'Bookmark';

    var $hasAndBelongsToMany =  array('Tag' =>
                                    array('className'    => 'Tag',
                                            'joinTable'    =>
'bookmarks_tags',
                                            'foreignKey'   =>
'bookmark_id',
                                            'associationForeignKey'=>
'tag_id',
                                            'conditions'   => '',
                                            'order'        => '',
                                            'limit'        => '',
                                            'unique'       => true,
                                            'finderQuery'  => '',
                                            'deleteQuery'  => '',
                                    )
                                );
    function bindTag() {

        $this->bindModel(
            array(
                'hasOne' => array(
                    'BookmarkTagAssoc' => array(
                        'className' => 'BookmarkTag'
                    )
                )
            )
        );
    }
}

# bookmarks_controller.php

    function admin_tag($id) {

        $this->uses[] = 'BookmarkTag';
        $constraint['BookmarkTagAssoc.tag_id'] = $id;

        $this->Bookmark->bindTag();

        // init() resets the association, so i'm creating it again
        list($order,$limit,$page) = $this->Pagination-
>init($constraint, null, $this->pagerSettings);

        $this->Bookmark->bindTag();

        $tempBookmarks = $this->Bookmark->findAll($constraint, NULL,
$order, $limit, $page);

        //... doing stuff with results here
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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