Saturday, June 25, 2011

Re: habtm



Removing or adding associations using bind- and unbindModel() only works for the next find operation only unless the second parameter has been set to false. If the second parameter has been set to false, the bind remains in place for the remainder of the request. 

try:

$this->Post->unbindModel(array('hasAndBelongsToMany'=>array('Tag')), false);


this is because paginate first does a count query ...


Andras Kende


On Jun 25, 2011, at 3:14 AM, Prabha Vathi wrote:

Hi,

I m not able to get good example for habtm.
I tried something.
$this->Post->unbindModel(array('hasAndBelongsToMany'=>array('Tag')));
        $this->Post->bindModel(
            array(
                'hasOne'=>array(
                    'PostsTag'=>array(
                        'foreignKey'=>false,
                        'type'=>'INNER',
                        'conditions'=>array('PostsTag.post_id = Post.id')
                    ),
                    'Tag'=>array(
                        'foreignKey'=>false,
                        'type'=>'INNER',
                        'conditions'=>array(
                            'Tag.id = PostsTag.tag_id'
                        )
                    )
                )
            )
        );
$posts = $this->Post->find('all', array('group' => array('Post.id'))); //working
Find all works, if i add conditions.
But if i comment find and add the following line it is not working.
$this->paginate = array('conditions' => array('Post.status' => 'active','Tag.tag_machine_value' => $name),'limit' => 2,'group' => array('Post.id')); //not working

Any Idea?

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: