Pages

Wednesday, September 11, 2013

Cakephp-HABTM implementation

HABTM

"Has and Belongs To Many"

A "Post" may have many "Tags" and may belong to many tags

In Post's Model


 public $hasAndBelongsToMany = array(  
  'Tag' => array(  
   'className' => 'Tag',  
   'joinTable' => 'posts_tags',  
   'foreignKey' => 'post_id',  
   'associationForeignKey' => 'tag_id',  
   'unique' => 'keepExisting',  
  )  
  );  

No comments:

Post a Comment