当前位置: 首页>>代码示例>>PHP>>正文


PHP Table::hasOne方法代码示例

本文整理汇总了PHP中Cake\ORM\Table::hasOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::hasOne方法的具体用法?PHP Table::hasOne怎么用?PHP Table::hasOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\ORM\Table的用法示例。


在下文中一共展示了Table::hasOne方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setupFieldAssociations

 /**
  * Creates the associations between the bound table and every field passed to
  * this method.
  *
  * Additionally it creates a `i18n` HasMany association that will be
  * used for fetching all versions for each record in the bound table
  *
  * @param string $table the table name to use for storing each field version
  * @return void
  */
 public function setupFieldAssociations($table)
 {
     $alias = $this->_table->alias();
     foreach ($this->_fields() as $field) {
         $name = $this->_table->alias() . '_' . $field . '_version';
         $target = TableRegistry::get($name);
         $target->table($table);
         $this->_table->hasOne($name, ['targetTable' => $target, 'foreignKey' => 'foreign_key', 'joinType' => 'LEFT', 'conditions' => [$name . '.model' => $alias, $name . '.field' => $field], 'propertyName' => $field . '_version']);
     }
     $this->_table->hasMany($table, ['foreignKey' => 'foreign_key', 'strategy' => 'subquery', 'conditions' => ["{$table}.model" => $alias], 'propertyName' => '__version', 'dependent' => true]);
 }
开发者ID:chris48s,项目名称:cakephp-version,代码行数:21,代码来源:VersionBehavior.php

示例2: setupFieldAssociations

 /**
  * Creates the associations between the bound table and every field passed to
  * this method.
  *
  * Additionally it creates a `i18n` HasMany association that will be
  * used for fetching all translations for each record in the bound table
  *
  * @param array $fields list of fields to create associations for
  * @param string $table the table name to use for storing each field translation
  * @param string $model the model field value
  * @param string $strategy the strategy used in the _i18n association
  *
  * @return void
  */
 public function setupFieldAssociations($fields, $table, $model, $strategy)
 {
     $targetAlias = $this->_translationTable->alias();
     $alias = $this->_table->alias();
     $filter = $this->_config['onlyTranslated'];
     $tableLocator = $this->tableLocator();
     foreach ($fields as $field) {
         $name = $alias . '_' . $field . '_translation';
         if (!$tableLocator->exists($name)) {
             $fieldTable = $tableLocator->get($name, ['className' => $table, 'alias' => $name, 'table' => $this->_translationTable->table()]);
         } else {
             $fieldTable = $tableLocator->get($name);
         }
         $conditions = [$name . '.model' => $model, $name . '.field' => $field];
         if (!$this->_config['allowEmptyTranslations']) {
             $conditions[$name . '.content !='] = '';
         }
         $this->_table->hasOne($name, ['targetTable' => $fieldTable, 'foreignKey' => 'foreign_key', 'joinType' => $filter ? 'INNER' : 'LEFT', 'conditions' => $conditions, 'propertyName' => $field . '_translation']);
     }
     $conditions = ["{$targetAlias}.model" => $model];
     if (!$this->_config['allowEmptyTranslations']) {
         $conditions["{$targetAlias}.content !="] = '';
     }
     $this->_table->hasMany($targetAlias, ['className' => $table, 'foreignKey' => 'foreign_key', 'strategy' => $strategy, 'conditions' => $conditions, 'propertyName' => '_i18n', 'dependent' => true]);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:39,代码来源:TranslateBehavior.php

示例3: versionAssociation

 /**
  * Returns association object for all versions or single field version.
  *
  * @param string|null $field Field name for per-field association.
  * @param array $options Association options.
  * @return \Cake\ORM\Association
  */
 public function versionAssociation($field = null, $options = [])
 {
     $name = $this->_associationName($field);
     if (!$this->_table->associations()->has($name)) {
         $model = $this->_config['referenceName'];
         if ($field) {
             $this->_table->hasOne($name, $options + ['className' => $this->_config['versionTable'], 'foreignKey' => $this->_config['foreignKey'], 'joinType' => 'LEFT', 'conditions' => [$name . '.model' => $model, $name . '.field' => $field], 'propertyName' => $field . '_version']);
         } else {
             $this->_table->hasMany($name, $options + ['className' => $this->_config['versionTable'], 'foreignKey' => $this->_config['foreignKey'], 'strategy' => 'subquery', 'conditions' => ["{$name}.model" => $model], 'propertyName' => '__version', 'dependent' => true]);
         }
     }
     return $this->_table->association($name);
 }
开发者ID:josegonzalez,项目名称:cakephp-version,代码行数:20,代码来源:VersionBehavior.php

示例4: setupFieldAssociations

 /**
  * Creates the associations between the bound table and every field passed to
  * this method.
  *
  * Additionally it creates a `i18n` HasMany association that will be
  * used for fetching all translations for each record in the bound table
  *
  * @param array $fields list of fields to create associations for
  * @param string $table the table name to use for storing each field translation
  * @param array $fieldConditions conditions for finding fields
  * @param string $strategy the strategy used in the _i18n association
  *
  * @return void
  */
 public function setupFieldAssociations($fields, $table, $fieldConditions, $strategy)
 {
     $targetAlias = $this->_translationTable->alias();
     $alias = $this->_table->alias();
     $filter = $this->_config['onlyTranslated'];
     foreach ($fields as $field) {
         $name = $alias . '_' . $field . '_translation';
         $conditions = [$name . '.model' => $fieldConditions['model'], $name . '.field' => $field];
         foreach ($fieldConditions as $fieldName => $fieldValue) {
             $conditions[$name . '.' . $fieldName] = $fieldValue;
         }
         if (!TableRegistry::exists($name)) {
             $fieldTable = TableRegistry::get($name, ['className' => $table, 'alias' => $name, 'table' => $this->_translationTable->table()]);
         } else {
             $fieldTable = TableRegistry::get($name);
         }
         $this->_table->hasOne($name, ['targetTable' => $fieldTable, 'foreignKey' => 'foreign_key', 'joinType' => $filter ? 'INNER' : 'LEFT', 'conditions' => $conditions, 'propertyName' => $field . '_translation']);
     }
     $this->_table->hasMany($targetAlias, ['className' => $table, 'foreignKey' => 'foreign_key', 'strategy' => $strategy, 'conditions' => ["{$targetAlias}.model" => $fieldConditions['model']], 'propertyName' => '_i18n', 'dependent' => true]);
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:34,代码来源:TranslateBehavior.php

示例5: testHasOnePlugin

 /**
  * Test has one with a plugin model
  *
  * @return void
  */
 public function testHasOnePlugin()
 {
     $options = ['className' => 'TestPlugin.Comments'];
     $table = new Table(['table' => 'users']);
     $hasOne = $table->hasOne('Comments', $options);
     $this->assertInstanceOf('Cake\\ORM\\Association\\HasOne', $hasOne);
     $this->assertSame('Comments', $hasOne->name());
     $hasOneTable = $hasOne->target();
     $this->assertSame('Comments', $hasOne->alias());
     $this->assertSame('TestPlugin.Comments', $hasOne->registryAlias());
     $options = ['className' => 'TestPlugin.Comments'];
     $table = new Table(['table' => 'users']);
     $hasOne = $table->hasOne('TestPlugin.Comments', $options);
     $this->assertInstanceOf('Cake\\ORM\\Association\\HasOne', $hasOne);
     $this->assertSame('Comments', $hasOne->name());
     $hasOneTable = $hasOne->target();
     $this->assertSame('Comments', $hasOne->alias());
     $this->assertSame('TestPlugin.Comments', $hasOne->registryAlias());
 }
开发者ID:jdaosavanh,项目名称:clickerwebapp,代码行数:24,代码来源:TableTest.php

示例6: testHasOne

 /**
  * Tests that hasOne() creates and configures correctly the association
  *
  * @return void
  */
 public function testHasOne()
 {
     $options = ['foreignKey' => 'user_id', 'conditions' => ['b' => 'c']];
     $table = new Table(['table' => 'users']);
     $hasOne = $table->hasOne('profile', $options);
     $this->assertInstanceOf('Cake\\ORM\\Association\\HasOne', $hasOne);
     $this->assertSame($hasOne, $table->association('profile'));
     $this->assertEquals('profile', $hasOne->name());
     $this->assertEquals('user_id', $hasOne->foreignKey());
     $this->assertEquals(['b' => 'c'], $hasOne->conditions());
     $this->assertSame($table, $hasOne->source());
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:17,代码来源:TableTest.php

示例7: __construct

 /**
  * {@inheritDoc}
  */
 public function __construct(Table $table, array $config = [])
 {
     $config['pk'] = $table->primaryKey();
     $config['tableAlias'] = (string) Inflector::underscore($table->table());
     $table->hasOne('Search.SearchDatasets', ['foreignKey' => 'entity_id', 'conditions' => ['SearchDatasets.table_alias' => $config['tableAlias']], 'dependent' => true]);
     parent::__construct($table, $config);
 }
开发者ID:quickapps-plugins,项目名称:search,代码行数:10,代码来源:GenericEngine.php


注:本文中的Cake\ORM\Table::hasOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。