Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Using unBindModel() in CakePHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 486
    Comment on it

    If we have to many tables in our project and we have many association between them. So whenever we use one of the model in our controller the other model which are associated with it , automatically get attached with user data .

    Sometime we don't want  this data, for that purpose we use unBind function for unbinding models.

    Below is the example in which country model is associated with state model by hasMany relationship. So whenever we use country model in our controller the state model which are associated with it , automatically get attached with user data .

    
    class Country extends AppModel {
    
    
    
            public $hasMany = array(
           'State' => array(
                 'className' => 'State',
            
             ),
         );
    
    	
    }

    Below is the logic for unbinding models.

    
     public function unBind(){
       
       $this->Country->unBindModel(array('hasMany'=>array('State')));
       $data = $this->Country->find("all", array('limit'=>4));
     }

    To unbindModel permanently we have to add false with unbind function.

    $this->Country->unBindModel(array(hasMany=>array('State')),false); 

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: