Код: Выделить всё
namespace app\models;
use yii\db\ActiveRecord;
class Customer extends ActiveRecord
{
const STATUS_INACTIVE = 0;
const STATUS_ACTIVE = 1;
/**
* @return string the name of the table associated with this ActiveRecord class.
*/
public static function tableName()
{
return '{{customer}}';
}
public function getOrders()
{
return $this->hasMany(Order::class, ['customer_id' => 'id']);
}
public static function getStatuses()
{
return [
self::STATUS_INACTIVE => 'Inactive',
self::STATUS_ACTIVE => 'Active',
];
}
public function getStatus()
{
return self::getStatuses()[$this->status];
}
}
Код: Выделить всё
$customers = Customer::find()->with('orders')->all();
Код: Выделить всё
$customers = Customer::find()->with('orders', 'status')->all();