HABTM stands for Has And Belongs To Many.
Its is a cake php associations that we defined in a models for accesing associated data across different entities over the database tables.
Example - A product have more then one tags, and in the same case tag may also belongs to one or more product. also we can see the structured image for HABTM.
Model will looks like :-
/**
* Post Model
*
* @property Tag $Tag
*/
class Post extends AppModel {
/**
* Display field
*
* @var string
*/
public $displayField = 'name';
/**
* Validation rules
*
* @var array
*/
public $validate = array( );
/**
* hasAndBelongsToMany associations
*
* @var array
*/
public $hasAndBelongsToMany = array(
'Tag' => array(
'className' => 'Tag',
'joinTable' => 'posts_tags',
'foreignKey' => 'post_id',
'associationForeignKey' => 'tag_id',
'unique' => 'keepExisting',
)
);
}
0 Comment(s)