for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @copyright Copyright (c) Flipbox Digital Limited
* @license https://flipboxfactory.com/software/domains/license
* @link https://www.flipboxfactory.com/software/domains/
*/
namespace flipbox\domains\records\traits;
use Craft;
use craft\base\FieldInterface;
use craft\records\Field as FieldRecord;
use flipbox\ember\records\traits\ActiveRecord;
use yii\db\ActiveQueryInterface;
* @author Flipbox Factory <[email protected]>
* @since 1.0.0
trait FieldAttribute
{
use ActiveRecord,
FieldRules,
FieldMutator;
* Get associated fieldId
*
* @return int|null
public function getFieldId()
$id = $this->getAttribute('fieldId');
if (null === $id && null !== $this->field) {
$id = $this->fieldId = $this->field->id;
}
return $id;
* @return FieldInterface|null
protected function resolveField()
if ($model = $this->resolveFieldFromRelation()) {
return $model;
return $this->resolveFieldFromId();
private function resolveFieldFromRelation()
if (false === $this->isRelationPopulated('fieldRecord')) {
return null;
/** @var FieldRecord $record */
$record = $this->getRelation('fieldRecord');
if (null === $record) {
return Craft::$app->getFields()->getFieldById($record->id);
* Get the associated Field
* @return ActiveQueryInterface
public function getFieldRecord()
return $this->hasOne(
FieldRecord::class,
['fieldId' => 'id']
);