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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 282
    Comment on it

    Hello Readers Four associations types used in cakePHP is explained here in a short and simple way. Hope this will be helpful to all.

     belongTo:
    If table movie has a field that refrences table director, then table movie "belongTo" table director. Every record in the movie table says "I belong to a record in table director"
         

    class movieTable extends Table
    {
    
        public function initialize(array $config)
        {
            $this->belongsTo('director');
        }
    
    }

     hasOne:
     If only a single record in the table director has a field that refrence table movie, then the table movie is said to "hasOne" table director.Every record in this table will say that it will have one  record in table director that point to movie.

    class movieTable extends director
    {
        public function initialize(array $config)
        {
            $this->hasOne('Addresses');
        }
    }
    
    


     hasMany:
    If a table director has a field that refrences table movie, and multiple record in table director can point to the same moviejtable record, then table movie is said to "hasMany" table director.

    class movieTable extends director
    {
    
        public function initialize(array $config)
        {
            $this->hasMany('Comments');
        }
    }


     hasAndBelongsToMany:
    In every record in table movie can link to multiple reference in table director, and every record in the table director can be linked to by multiple movie records, table movie is said to "hasAndBelongToMany" table director.

    class MovieTable extends director
    {
    
        public function initialize(array $config)
        {
            $this->belongsToMany('Tags');
        }
    }



     

 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: