api
This commit is contained in:
@ -15,6 +15,7 @@ use function Symfony\Component\String\s;
|
||||
* @property int|null $type
|
||||
* @property int|null $price
|
||||
* @property int|null $status
|
||||
* @property int $product_category_id
|
||||
*
|
||||
* @property Company $company
|
||||
*/
|
||||
@ -51,7 +52,7 @@ class Product extends \yii\db\ActiveRecord
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'product';
|
||||
}
|
||||
@ -59,11 +60,11 @@ class Product extends \yii\db\ActiveRecord
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
[['title', 'article', 'company_id'], 'required'],
|
||||
[['company_id', 'type', 'price', 'status'], 'integer'],
|
||||
[['title', 'article', 'company_id', 'product_category_id'], 'required'],
|
||||
[['company_id', 'type', 'price', 'status', 'product_category_id'], 'integer'],
|
||||
[['title', 'article'], 'string', 'max' => 255],
|
||||
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
|
||||
];
|
||||
@ -72,7 +73,7 @@ class Product extends \yii\db\ActiveRecord
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
public function attributeLabels(): array
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
@ -82,6 +83,7 @@ class Product extends \yii\db\ActiveRecord
|
||||
'type' => 'Тип',
|
||||
'price' => 'Цена',
|
||||
'status' => 'Статус',
|
||||
'product_category_id' => 'Категория',
|
||||
];
|
||||
}
|
||||
|
||||
@ -90,8 +92,16 @@ class Product extends \yii\db\ActiveRecord
|
||||
*
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getCompany()
|
||||
public function getCompany(): \yii\db\ActiveQuery
|
||||
{
|
||||
return $this->hasOne(Company::class, ['id' => 'company_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getProductCategory(): \yii\db\ActiveQuery
|
||||
{
|
||||
return $this->hasOne(ProductCategory::class, ['id' => 'product_category_id']);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user