diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index f239267..640affa 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -14,6 +14,7 @@ use GuzzleHttp\Exception\ClientException; use yii\base\InvalidConfigException; use yii\base\NotSupportedException; +use yii\base\UnknownPropertyException; use yii\db\BaseActiveRecord; use yii\helpers\Inflector; use yii\helpers\StringHelper; @@ -235,4 +236,19 @@ public function unlinkAll($name, $delete = false) { throw new NotSupportedException('unlinkAll() is not supported by RestClient, use unlink() instead.'); } + + /** + * @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); + } }