当前位置: 首页>>代码示例>>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;未经允许,请勿转载。