mirror of
https://github.com/yiisoft/yii2.git
synced 2025-12-05 04:27:46 +08:00
@@ -40,6 +40,17 @@ class Order extends ActiveRecord
|
||||
->via('orderItems')->orderBy('id');
|
||||
}
|
||||
|
||||
public function getItemsWithNullFK()
|
||||
{
|
||||
return $this->hasMany(Item::className(), ['id' => 'item_id'])
|
||||
->via('orderItemsWithNullFK');
|
||||
}
|
||||
|
||||
public function getOrderItemsWithNullFK()
|
||||
{
|
||||
return $this->hasMany(OrderItemWithNullFK::className(), ['order_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getItemsInOrder1()
|
||||
{
|
||||
return $this->hasMany(Item::className(), ['id' => 'item_id'])
|
||||
@@ -56,12 +67,19 @@ class Order extends ActiveRecord
|
||||
})->orderBy('name');
|
||||
}
|
||||
|
||||
// public function getBooks()
|
||||
// {
|
||||
// return $this->hasMany('Item', ['id' => 'item_id'])
|
||||
// ->viaTable('order_item', ['order_id' => 'id'])
|
||||
// ->where(['category_id' => 1]);
|
||||
// }
|
||||
public function getBooks()
|
||||
{
|
||||
return $this->hasMany(Item::className(), ['id' => 'item_id'])
|
||||
->via('orderItems')
|
||||
->where(['category_id' => 1]);
|
||||
}
|
||||
|
||||
public function getBooksWithNullFK()
|
||||
{
|
||||
return $this->hasMany(Item::className(), ['id' => 'item_id'])
|
||||
->via('orderItemsWithNullFK')
|
||||
->where(['category_id' => 1]);
|
||||
}
|
||||
|
||||
public function beforeSave($insert)
|
||||
{
|
||||
@@ -90,6 +108,5 @@ class Order extends ActiveRecord
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,21 +4,7 @@ namespace yiiunit\data\ar\elasticsearch;
|
||||
|
||||
/**
|
||||
* Class OrderItem
|
||||
*
|
||||
* @property integer $order_id
|
||||
* @property integer $item_id
|
||||
* @property integer $quantity
|
||||
* @property string $subtotal
|
||||
*/
|
||||
class OrderItemWithNullFK extends ActiveRecord
|
||||
class OrderItemWithNullFK extends OrderItem
|
||||
{
|
||||
public function attributes()
|
||||
{
|
||||
return ['order_id', 'item_id', 'quantity', 'subtotal'];
|
||||
}
|
||||
|
||||
public static function tableName()
|
||||
{
|
||||
return 'order_item_with_null_fk';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,26 +4,7 @@ namespace yiiunit\data\ar\elasticsearch;
|
||||
|
||||
/**
|
||||
* Class Order
|
||||
*
|
||||
* @property integer $id
|
||||
* @property integer $customer_id
|
||||
* @property integer $created_at
|
||||
* @property string $total
|
||||
*/
|
||||
class OrderWithNullFK extends ActiveRecord
|
||||
class OrderWithNullFK extends Order
|
||||
{
|
||||
public static function primaryKey()
|
||||
{
|
||||
return ['id'];
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return ['id', 'customer_id', 'created_at', 'total'];
|
||||
}
|
||||
|
||||
public static function tableName()
|
||||
{
|
||||
return 'order_with_null_fk';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user