Files
yii2/tests/data/ar/OrderWithConstructor.php
Paul Klimov d68789a195 Fixes #13779, fixes #5786
- #13779: Fixed `yii\db\ActiveRecord::joinWith()` unable to use relation defined via attached behavior.
- #5786: Allowed to use custom constructors in ActiveRecord-based classes.
2017-08-29 15:13:28 +03:00

56 lines
1.3 KiB
PHP

<?php
namespace yiiunit\data\ar;
/**
* OrderWithConstructor
*
* @property int $id
* @property int $customer_id
* @property int $created_at
* @property string $total
*
* @property OrderItemWithConstructor $orderItems
* @property CustomerWithConstructor $customer
* @property CustomerWithConstructor $customerJoinedWithProfile
*/
class OrderWithConstructor extends ActiveRecord
{
public static function tableName()
{
return 'order';
}
public function __construct($id)
{
$this->id = $id;
$this->created_at = time();
parent::__construct();
}
public static function instance($refresh = false)
{
return self::instantiate([]);
}
public static function instantiate($row)
{
return (new \ReflectionClass(static::className()))->newInstanceWithoutConstructor();
}
public function getCustomer()
{
return $this->hasOne(CustomerWithConstructor::className(), ['id' => 'customer_id']);
}
public function getCustomerJoinedWithProfile()
{
return $this->hasOne(CustomerWithConstructor::className(), ['id' => 'customer_id'])
->joinWith('profile');
}
public function getOrderItems()
{
return $this->hasMany(OrderItemWithConstructor::className(), ['order_id' => 'id'])->inverseOf('order');
}
}