本文整理汇总了PHP中yii\db\BaseActiveRecord::populateRecord方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseActiveRecord::populateRecord方法的具体用法?PHP BaseActiveRecord::populateRecord怎么用?PHP BaseActiveRecord::populateRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\BaseActiveRecord
的用法示例。
在下文中一共展示了BaseActiveRecord::populateRecord方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populateRecord
/**
* @inheritdoc
*/
public static function populateRecord($record, $row)
{
$columns = static::getTableSchema()->columns;
foreach ($row as $name => $value) {
if (isset($columns[$name])) {
$row[$name] = $columns[$name]->phpTypecast($value);
}
}
parent::populateRecord($record, $row);
}
示例2: populateRecord
/**
* Populates an active record object using a xunsearch result document
*
* @param ActiveRecord $record the record to be populated.
* @param \XSDocument $doc
*/
public static function populateRecord($record, $doc)
{
parent::populateRecord($record, $doc->getFields());
$record->setInternalDoc($doc);
}
示例3: populateRecord
/**
* @inheritdoc
*/
public static function populateRecord($record, $row)
{
$attributes = [];
if (isset($row['_source'])) {
$attributes = $row['_source'];
}
if (isset($row['fields'])) {
// reset fields in case it is scalar value TODO use field metadata for this
foreach ($row['fields'] as $key => $value) {
if (count($value) == 1) {
$row['fields'][$key] = reset($value);
}
}
$attributes = array_merge($attributes, $row['fields']);
}
parent::populateRecord($record, $attributes);
$pk = static::primaryKey()[0];
//TODO should always set ID in case of fields are not returned
if ($pk === '_id') {
$record->_id = $row['_id'];
}
$record->_highlight = isset($row['highlight']) ? $row['highlight'] : null;
$record->_score = isset($row['_score']) ? $row['_score'] : null;
$record->_version = isset($row['_version']) ? $row['_version'] : null;
// TODO version should always be available...
}
示例4: populateRecord
/**
* @inheritdoc
*/
public static function populateRecord($record, $row)
{
$columns = static::getIndexSchema()->columns;
foreach ($row as $name => $value) {
if (isset($columns[$name]) && $columns[$name]->isMva) {
$row[$name] = explode(',', $value);
}
}
parent::populateRecord($record, $row);
}
示例5: populateRecord
/**
* Populates an active record object using a row of data from the database/storage.
*
* This is an internal method meant to be called to create active record objects after
* fetching data from the database. It is mainly used by [[ActiveQuery]] to populate
* the query results into active records.
*
* When calling this method manually you should call [[afterFind()]] on the created
* record to trigger the [[EVENT_AFTER_FIND|afterFind Event]].
*
* @param static $record The record to be populated. In most cases this will be an instance
* created by [[instantiate()]] beforehand.
* @param array $row Attribute values (name => value).
* @return void
*/
public static function populateRecord($record, $row)
{
$responseData = ArrayHelper::getValue($row, Query::RESPONSE_KEY_PARAM);
unset($row[Query::RESPONSE_KEY_PARAM]);
parent::populateRecord($record, $row);
if (!empty($responseData)) {
$record->_responseData = $responseData;
}
}
示例6: populateRecord
/**
* @inheritdoc
*/
public static function populateRecord($record, $row)
{
$columns = static::getIndexSchema()->columns;
foreach ($row as $name => $value) {
if (isset($columns[$name])) {
if ($columns[$name]->isMva) {
$mvaValue = explode(',', $value);
$row[$name] = array_map([$columns[$name], 'phpTypecast'], $mvaValue);
} else {
$row[$name] = $columns[$name]->phpTypecast($value);
}
}
}
parent::populateRecord($record, $row);
}
示例7: populateRecord
/**
* @inheritdoc
* @throws \yii\base\UnknownPropertyException
*/
public static function populateRecord($record, $row)
{
$attributes = array_flip($record->attributes());
foreach ($attributes as $attributeName => $attributeValue) {
if (!array_key_exists($attributeName, $row)) {
throw new UnknownPropertyException("Attribute `{$attributeName}` not found in API response. Available fields: " . implode(', ', array_keys($row)) . '.');
}
}
parent::populateRecord($record, $row);
}
示例8: populateRecord
/**
* @param BaseActiveRecord $record
* @param array $row
*/
public static function populateRecord($record, $row)
{
// setup @class if not exists - required attribute
if (is_array($row) && empty($row['@class'])) {
Yii::info('Setup required empty @class(`' . $record::tableName() . '`) for record');
$row['@class'] = $record::tableName();
}
BaseActiveRecord::populateRecord($record, $row);
}
示例9: populateRecord
/**
* @inheritdoc
*
* @param ActiveRecord $record the record to be populated. In most cases this will be an instance
* created by [[instantiate()]] beforehand.
* @param array $row attribute values (name => value)
*/
public static function populateRecord($record, $row)
{
$attributes = [];
// if (isset($row['_source'])) {
// $attributes = $row['_source'];
// }
//
// if (isset($row['fields'])) {
// // reset fields in case it is scalar value
// $arrayAttributes = $record->arrayAttributes();
// foreach($row['fields'] as $key => $value) {
// if (!isset($arrayAttributes[$key]) && count($value) == 1) {
// $row['fields'][$key] = reset($value);
// }
// }
// $attributes = array_merge($attributes, $row['fields']);
// }
$attributes = $row;
// just a plain document returned as array from query
parent::populateRecord($record, $attributes);
$pk = static::primaryKey()[0];
//TODO should always set ID in case of fields are not returned
if ($pk === '_id') {
$record->_id = $row['_id'];
}
// $record->_highlight = isset($row['highlight']) ? $row['highlight'] : null;
// $record->_score = isset($row['_score']) ? $row['_score'] : null;
$record->_attachments = isset($row['_attachments']) ? $row['_attachments'] : [];
$record->_rev = isset($row['_rev']) ? $row['_rev'] : null;
// TODO version should always be available...
}
示例10: populateRecord
public static function populateRecord($record, $row)
{
$attributes = [];
if (!empty($row)) {
$arrayAttributes = $record->arrayAttributes();
foreach ($row as $key => $value) {
if (!isset($arrayAttributes[$key])) {
$row[$key] = $value;
}
}
$attributes = array_merge($attributes, $row);
}
parent::populateRecord($record, $attributes);
$pk = static::primaryKey()[0];
if ($pk === 'objectId') {
$record->_id = $row['objectId'];
}
}