la_back/common/models/Order.php
2023-11-21 19:51:44 +03:00

110 lines
2.5 KiB
PHP
Executable File

<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "order".
*
* @property int $id
* @property int|null $user_id
* @property int|null $table_id
* @property int|null $strength
* @property string|null $amount
* @property int|null $status
* @property string|null $created_at
* @property string|null $updated_at
*
* @property OrderProduct[] $orderProducts
* @property Product[] $products
* @property Table $table
* @property User $user
* @property Product[] $tastes
*/
class Order extends \yii\db\ActiveRecord
{
const STATUS_NEW = 0;
const STATUS_IN_PROGRESS = 1;
const STATUS_DONE = 2;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'order';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['user_id', 'table_id', 'strength', 'status'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['amount'], 'string', 'max' => 255],
[['table_id'], 'exist', 'skipOnError' => true, 'targetClass' => Table::class, 'targetAttribute' => ['table_id' => 'id']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'table_id' => 'Table ID',
'strength' => 'Strength',
'amount' => 'Amount',
'status' => 'Status',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
/**
* Gets query for [[OrderProducts]].
*
* @return \yii\db\ActiveQuery
*/
public function getOrderProducts()
{
return $this->hasMany(OrderProduct::class, ['order_id' => 'id']);
}
/**
* Gets query for [[Table]].
*
* @return \yii\db\ActiveQuery
*/
public function getTable()
{
return $this->hasOne(Table::class, ['id' => 'table_id']);
}
/**
* Gets query for [[User]].
*
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::class, ['id' => 'user_id']);
}
/**
* Gets query for [[Products]].
*
* @return \yii\db\ActiveQuery
*/
public function getProducts()
{
return $this->hasMany(Product::class, ['id' => 'product_id'])
->viaTable('order_product', ['order_id' => 'id']);
}
}