Cake\ORM\Association\BelongsToMany::targetForeignKey PHP Method

targetForeignKey() public method

If no parameters are passed current field is returned
public targetForeignKey ( string | null $key = null ) : string
$key string | null the key to be used to link both tables together
return string
    public function targetForeignKey($key = null)
    {
        if ($key === null) {
            if ($this->_targetForeignKey === null) {
                $this->_targetForeignKey = $this->_modelKey($this->target()->alias());
            }
            return $this->_targetForeignKey;
        }
        return $this->_targetForeignKey = $key;
    }

Usage Example

コード例 #1
0
ファイル: BelongsToManyTest.php プロジェクト: rashmi/newrepo
 /**
  * Tests that targetForeignKey() returns the correct configured value
  *
  * @return void
  */
 public function testTargetForeignKey()
 {
     $assoc = new BelongsToMany('Test', ['sourceTable' => $this->article, 'targetTable' => $this->tag]);
     $this->assertEquals('tag_id', $assoc->targetForeignKey());
     $assoc->targetForeignKey('another_key');
     $this->assertEquals('another_key', $assoc->targetForeignKey());
     $assoc = new BelongsToMany('Test', ['sourceTable' => $this->article, 'targetTable' => $this->tag, 'targetForeignKey' => 'foo']);
     $this->assertEquals('foo', $assoc->targetForeignKey());
 }