unbindModel call in CakePhp. How does it work?

前端 未结 3 1574
星月不相逢
星月不相逢 2021-01-12 05:55

How does unbindModel happen in cake?

$this->User->unbindModel(array(\'hasAndBelongsToMany\' => array(\'Friend\')));

I wrote this i

3条回答
  •  我在风中等你
    2021-01-12 06:54

    Try This:

    $this->Leader->find('all');
    
    // Let's remove the hasMany...
    $this->Leader->unbindModel(
        array('hasMany' => array('Follower'))
    );
    
    // Now using a find function will return
    // Leaders, with no Followers
    $this->Leader->find('all');
    
    // NOTE: unbindModel only affects the very next
    // find function. An additional find call will use
    // the configured association information.
    
    // We've already used find('all') after unbindModel(),
    // so this will fetch Leaders with associated
    // Followers once again...
    $this->Leader->find('all');
    

提交回复
热议问题