當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Table::belongsTo方法代碼示例

本文整理匯總了PHP中Cake\ORM\Table::belongsTo方法的典型用法代碼示例。如果您正苦於以下問題:PHP Table::belongsTo方法的具體用法?PHP Table::belongsTo怎麽用?PHP Table::belongsTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\ORM\Table的用法示例。


在下文中一共展示了Table::belongsTo方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * Constructor
  *
  * @param \Cake\ORM\Table $table Table who requested the behavior.
  * @param array $config Options.
  */
 public function __construct(Table $table, array $config = [])
 {
     parent::__construct($table, $config);
     $this->Table = $table;
     if ($this->config('created_by')) {
         $this->Table->belongsTo('CreatedBy', ['foreignKey' => $this->config('created_by'), 'className' => $this->config('userModel'), 'propertyName' => $this->config('createdByPropertyName')]);
     }
     if ($this->config('modified_by')) {
         $this->Table->belongsTo('ModifiedBy', ['foreignKey' => $this->config('modified_by'), 'className' => $this->config('userModel'), 'propertyName' => $this->config('modifiedByPropertyName')]);
     }
 }
開發者ID:Tomicapo,項目名稱:cakephp-utils,代碼行數:17,代碼來源:WhoDidItBehavior.php

示例2: __construct

 /**
  * Constructor.
  *
  * @param \Cake\ORM\Table $table The table this behavior is attached to
  * @param array $config Configuration array for this behavior
  */
 public function __construct(Table $table, array $config = [])
 {
     $this->_table = $table;
     parent::__construct($this->_table, $config);
     if ($this->config('autoBind')) {
         if ($this->_table->hasField($this->config('createdByField'))) {
             $this->_table->belongsTo('CreatedBy', ['className' => $this->config('userModel'), 'foreignKey' => $this->config('createdByField'), 'propertyName' => 'created_by']);
         }
         if ($this->_table->hasField($this->config('modifiedByField'))) {
             $this->_table->belongsTo('ModifiedBy', ['className' => $this->config('userModel'), 'foreignKey' => $this->config('modifiedByField'), 'propertyName' => 'modified_by']);
         }
     }
 }
開發者ID:quickapps-plugins,項目名稱:user,代碼行數:19,代碼來源:WhoDidItBehavior.php

示例3: _generateJunctionAssociations

 /**
  * Generate associations on the junction table as necessary
  *
  * Generates the following associations:
  *
  * - junction belongsTo source e.g. ArticlesTags belongsTo Tags
  * - junction belongsTo target e.g. ArticlesTags belongsTo Articles
  *
  * You can override these generated associations by defining associations
  * with the correct aliases.
  *
  * @param \Cake\ORM\Table $junction The junction table.
  * @param \Cake\ORM\Table $source The source table.
  * @param \Cake\ORM\Table $target The target table.
  * @return void
  */
 protected function _generateJunctionAssociations($junction, $source, $target)
 {
     $tAlias = $target->alias();
     $sAlias = $source->alias();
     if (!$junction->association($tAlias)) {
         $junction->belongsTo($tAlias, ['foreignKey' => $this->targetForeignKey(), 'targetTable' => $target]);
     }
     if (!$junction->association($sAlias)) {
         $junction->belongsTo($sAlias, ['foreignKey' => $this->foreignKey(), 'targetTable' => $source]);
     }
 }
開發者ID:Mingyangzu,項目名稱:PHP-cakephp,代碼行數:27,代碼來源:BelongsToMany.php

示例4: testFindListWithAssociatedTable

 /**
  * Test find('list') with value field from associated table
  *
  * @return void
  */
 public function testFindListWithAssociatedTable()
 {
     $articles = new Table(['table' => 'articles', 'connection' => $this->connection]);
     $articles->belongsTo('Authors');
     $query = $articles->find('list', ['valueField' => 'author.name'])->contain(['Authors'])->order('articles.id');
     $this->assertEmpty($query->clause('select'));
     $expected = [1 => 'mariano', 2 => 'larry', 3 => 'mariano'];
     $this->assertSame($expected, $query->toArray());
 }
開發者ID:jdaosavanh,項目名稱:clickerwebapp,代碼行數:14,代碼來源:TableTest.php

示例5: testBelongsTo

 /**
  * Tests that belongsTo() creates and configures correctly the association
  *
  * @return void
  */
 public function testBelongsTo()
 {
     $options = ['foreignKey' => 'fake_id', 'conditions' => ['a' => 'b']];
     $table = new Table(['table' => 'dates']);
     $belongsTo = $table->belongsTo('user', $options);
     $this->assertInstanceOf('Cake\\ORM\\Association\\BelongsTo', $belongsTo);
     $this->assertSame($belongsTo, $table->association('user'));
     $this->assertEquals('user', $belongsTo->name());
     $this->assertEquals('fake_id', $belongsTo->foreignKey());
     $this->assertEquals(['a' => 'b'], $belongsTo->conditions());
     $this->assertSame($table, $belongsTo->source());
 }
開發者ID:neilan35,項目名稱:betterwindow1,代碼行數:17,代碼來源:TableTest.php


注:本文中的Cake\ORM\Table::belongsTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。