本文整理匯總了PHP中yii\db\ActiveRecord::hasMany方法的典型用法代碼示例。如果您正苦於以下問題:PHP ActiveRecord::hasMany方法的具體用法?PHP ActiveRecord::hasMany怎麽用?PHP ActiveRecord::hasMany使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::hasMany方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getTranslations
/**
* Relation to model translations
* @return ActiveQuery
* @since 2.0.0
*/
public function getTranslations()
{
return $this->owner->hasMany($this->translateClassName, [$this->translateForeignKey => $this->ownerPrimaryKey]);
}
示例2: hasMany
public function hasMany($class, $link, $alias = null)
{
$query = parent::hasMany($class, $link);
if ($alias == null) {
$alias = lcfirst(str_replace('_', '', $class::tableName()));
}
return $query->from([$alias => $class::tableName()]);
}
示例3: getTranslations
/**
* Relation to model translations
*
* @return ActiveQuery
*/
public function getTranslations()
{
return $this->owner->hasMany($this->translationModelName, [$this->translationOwnerField => $this->ownerPrimaryKey]);
}
示例4: hasMany
/**
* @inheritdoc
*/
public function hasMany($class, $link)
{
return parent::hasMany($this->replaceRelatedClass($class), $link);
}
示例5: hasMany
public function hasMany($class, $link)
{
$rclass = $this->replaceClassWithCurrentPathOne($class);
return parent::hasMany($rclass, $link);
}
示例6: hasMany
/**
* Declares a `has-many` relation.
* @param string $class the class name of the related record
* @param array $link the primary-foreign key constraint. The keys of the array refer to
* the attributes of the record associated with the `$class` model, while the values of the
* array refer to the corresponding attributes in **this** AR class.
* adjust the result to use the primary key as the array key
* @return ActiveQueryInterface the relational query object.
*/
public function hasMany($class, $link)
{
/* @var $class ActiveRecordInterface */
/* @var $query ActiveQuery */
$query = parent::hasMany($class, $link);
if ($query->multiple) {
$keys = $class::primaryKey();
if (count($keys) === 1) {
$query->indexBy = $keys[0];
} elseif (count($keys) === 2) {
$query->indexBy = $keys[1];
}
}
return $query;
}