src/Model/Behavior/TagBehavior.php
public function bindAssociations()
    {
        $config = $this->getConfig();
        $tagsAlias = $config['tagsAlias'];
        $tagsAssoc = $config['tagsAssoc'];
        $taggedAlias = $config['taggedAlias'];
        $taggedAssoc = $config['taggedAssoc'];

        $table = $this->_table;
        $tableAlias = $this->_table->getAlias();

        $assocConditions = [$taggedAlias . '.' . $this->getConfig('fkTableField') => $table->getTable()];

        if (!$table->hasAssociation($taggedAlias)) {
            $table->hasMany($taggedAlias, $taggedAssoc + [
                'foreignKey' => $tagsAssoc['foreignKey'],
                'conditions' => $assocConditions,
            ]);
        }

        if (!$table->hasAssociation($tagsAlias)) {
            $table->belongsToMany($tagsAlias, $tagsAssoc + [
                'through' => $table->{$taggedAlias}->getTarget(),
                'conditions' => $assocConditions,
            ]);
        }

        if (!$table->{$tagsAlias}->hasAssociation($tableAlias)) {
            $table->{$tagsAlias}
                ->belongsToMany($tableAlias, [
                    'className' => $table->getTable(),
                ] + $tagsAssoc);
        }

        if (!$table->{$taggedAlias}->hasAssociation($tableAlias)) {
            $table->{$taggedAlias}
                ->belongsTo($tableAlias, [
                    'className' => $table->getTable(),
                    'foreignKey' => $tagsAssoc['foreignKey'],
                    'conditions' => $assocConditions,
                    'joinType' => 'INNER',
                ]);
        }

        if (!$table->{$taggedAlias}->hasAssociation($tableAlias . $tagsAlias)) {
            $table->{$taggedAlias}
                ->belongsTo($tableAlias . $tagsAlias, [
                    'className' => $tagsAssoc['className'],
                    'foreignKey' => $tagsAssoc['targetForeignKey'],
                    'conditions' => $assocConditions,
                    'joinType' => 'INNER',
                ]);
        }
    }
public function bindAssociations()
    {
        $config = $this->getConfig();
        $tagsAlias = $config['tagsAlias'];
        $tagsAssoc = $config['tagsAssoc'];
        $taggedAlias = $config['taggedAlias'];
        $taggedAssoc = $config['taggedAssoc'];

        $table = $this->_table;
        $tableAlias = $this->_table->getAlias();

        $assocConditions = [$taggedAlias . '.' . $this->getConfig('fkTableField') => $table->getTable()];

        if (!$table->hasAssociation($taggedAlias)) {
            $table->hasMany($taggedAlias, $taggedAssoc + [
                'foreignKey' => $tagsAssoc['foreignKey'],
                'conditions' => $assocConditions,
            ]);
        }

        if (!$table->hasAssociation($tagsAlias)) {
            $table->belongsToMany($tagsAlias, $tagsAssoc + [
                'through' => $table->{$taggedAlias}->getTarget(),
                'conditions' => $assocConditions,
            ]);
        }

        if (!$table->{$tagsAlias}->hasAssociation($tableAlias)) {
            $table->{$tagsAlias}
                ->belongsToMany($tableAlias, [
                    'className' => $table->getTable(),
                ] + $tagsAssoc);
        }

        if (!$table->{$taggedAlias}->hasAssociation($tableAlias)) {
            $table->{$taggedAlias}
                ->belongsTo($tableAlias, [
                    'className' => $table->getTable(),
                    'foreignKey' => $tagsAssoc['foreignKey'],
                    'conditions' => $assocConditions,
                    'joinType' => 'INNER',
                ]);
        }

        if (!$table->{$taggedAlias}->hasAssociation($tableAlias . $tagsAlias)) {
            $table->{$taggedAlias}
                ->belongsTo($tableAlias . $tagsAlias, [
                    'className' => $tagsAssoc['className'],
                    'foreignKey' => $tagsAssoc['targetForeignKey'],
                    'conditions' => $assocConditions,
                    'joinType' => 'INNER',
                ]);
        }
    }
public function bindAssociations ( ) { $ config = $ this -> getConfig ( ) ; $ tagsAlias = $ config [ 'tagsAlias' ] ; $ tagsAssoc = $ config [ 'tagsAssoc' ] ; $ taggedAlias = $ config [ 'taggedAlias' ] ; $ taggedAssoc = $ config [ 'taggedAssoc' ] ; $ table = $ this -> _table ; $ tableAlias = $ this -> _table -> getAlias ( ) ; $ assocConditions = [ $ taggedAlias . '.' . $ this -> getConfig ( 'fkTableField' ) => $ table -> getTable ( ) ] ; if ( ! $ table -> hasAssociation ( $ taggedAlias ) ) { $ table -> hasMany ( $ taggedAlias , $ taggedAssoc + [ 'foreignKey' => $ tagsAssoc [ 'foreignKey' ] , 'conditions' => $ assocConditions , ] ) ; } if ( ! $ table -> hasAssociation ( $ tagsAlias ) ) { $ table -> belongsToMany ( $ tagsAlias , $ tagsAssoc + [ 'through' => $ table -> { $ taggedAlias } -> getTarget ( ) , 'conditions' => $ assocConditions , ] ) ; } if ( ! $ table -> { $ tagsAlias } -> hasAssociation ( $ tableAlias ) ) { $ table -> { $ tagsAlias } -> belongsToMany ( $ tableAlias , [ 'className' => $ table -> getTable ( ) , ] + $ tagsAssoc ) ; } if ( ! $ table -> { $ taggedAlias } -> hasAssociation ( $ tableAlias ) ) { $ table -> { $ taggedAlias } -> belongsTo ( $ tableAlias , [ 'className' => $ table -> getTable ( ) , 'foreignKey' => $ tagsAssoc [ 'foreignKey' ] , 'conditions' => $ assocConditions , 'joinType' => 'INNER' , ] ) ; } if ( ! $ table -> { $ taggedAlias } -> hasAssociation ( $ tableAlias . $ tagsAlias ) ) { $ table -> { $ taggedAlias } -> belongsTo ( $ tableAlias . $ tagsAlias , [ 'className' => $ tagsAssoc [ 'className' ] , 'foreignKey' => $ tagsAssoc [ 'targetForeignKey' ] , 'conditions' => $ assocConditions , 'joinType' => 'INNER' , ] ) ; } }
Binds all required associations if an association of the same name has
not already been configured.

@return void
Binds all required associations if an association of the same name has not already been configured .