Skip to content

alert2joe/cakephp_JoinTable_Behavior

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

cakephp_JoinTable_Behavior

##在MODEL 沒有設定 hasOne,hasMany... 的情況下,減少重復joins table,

##Usage

Use inside your model

public $actsAs = array('TTJoin');

post.php


//post model
case 01 : //quick use
            array(
             'joins' => $this->TTJoin(array('Comment.Post')),
             );

case 02 : //join 2 table
      array(
             'joins' => $this->TTJoin(array('Comment.Post','modelName.TTKEY')),
             );

case 01 : //quick over write default type
            array(
             'joins' => $this->TTJoin(array('Comment.Post.LEFT')),
             );


case 03 ://over write default value
         array(
             'joins' => $this->TTJoin(array(
                            'Comment.Post'=>array(
                                                'type'=>'INNER'
                                                )
                                        ),
             );
case 04 // no model join
        'joins' => $this->TTJoin(array('NoModel'=>array(
                        'table' => 'comment',
                        'alias' => 'Comment',
                        'type' => 'LEFT',
                        'conditions' => array(
                            'Post.id = Comment.post_id',
                        )
                    ))

in Comment.php

    function TTjoinLists(){
        return array(
            'Post'=> array( 
                        'type' => 'LEFT',
                        'conditions' => array(
                            'Post.id = Comment.post_id',
                        )
                    )
        );

     }

About

cakephp_JoinTable_Behavior

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages