Cake\ORM\Association\BelongsToMany::targetForeignKey PHP 메소드

targetForeignKey() 공개 메소드

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
리턴 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
 /**
  * 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());
 }