mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-21 14:37:21 +01:00
- #13779: Fixed `yii\db\ActiveRecord::joinWith()` unable to use relation defined via attached behavior. - #5786: Allowed to use custom constructors in ActiveRecord-based classes.
41 lines
875 B
PHP
41 lines
875 B
PHP
<?php
|
|
|
|
namespace yiiunit\data\ar;
|
|
|
|
/**
|
|
* OrderItemWithConstructor
|
|
*
|
|
* @property int $order_id
|
|
* @property int $item_id
|
|
* @property int $quantity
|
|
* @property string $subtotal
|
|
*/
|
|
class OrderItemWithConstructor extends ActiveRecord
|
|
{
|
|
public static function tableName()
|
|
{
|
|
return 'order_item';
|
|
}
|
|
|
|
public function __construct($item_id, $quantity)
|
|
{
|
|
$this->item_id = $item_id;
|
|
$this->quantity = $quantity;
|
|
parent::__construct();
|
|
}
|
|
|
|
public static function instance($refresh = false)
|
|
{
|
|
return self::instantiate([]);
|
|
}
|
|
|
|
public static function instantiate($row)
|
|
{
|
|
return (new \ReflectionClass(static::className()))->newInstanceWithoutConstructor();
|
|
}
|
|
|
|
public function getOrder()
|
|
{
|
|
return $this->hasOne(OrderWithConstructor::className(), ['id' => 'order_id']);
|
|
}
|
|
} |