Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • HABTM in cakephp?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 158
    Comment on it

    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',
      )
     );
    
    }
    
    HABTM in cakephp?

 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: