Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Unbinding Model in cakePHP

    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 399
    Comment on it

    Lets say there are two models named as User and Post. A User hasMany Post, so in our User model we have a relation like this :-

    class User extends AppModel{
    
    var $name = User;
    var $hasMany = array(Post=>array(foreignKey=>user_id));
    
    }
    

    Now whenever we use this model in our controller the above related model is also attached with user data. Some times we may not want this data, to do that we can unbind the model in controller like this :-

    $this->User->unbindModel(array(hasMany=>array(Post)));
    

    To unbindModel permanently for within a controller function we just add false at the end of unbinding like this:-

    $this->User->unbindModel(array(hasMany=>array(Post)),false);
    

    This will unbind the model permanently for that action inside the controller.

 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: