mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-14 13:25:23 +08:00
Merge branch 'master' of github.com:yiisoft/yii2
This commit is contained in:
@@ -35,6 +35,11 @@ class Customer extends ActiveRecord
|
|||||||
return $this->hasMany(Order::className(), ['customer_id' => 'id'])->orderBy('created_at');
|
return $this->hasMany(Order::className(), ['customer_id' => 'id'])->orderBy('created_at');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getOrdersWithNullFK()
|
||||||
|
{
|
||||||
|
return $this->hasMany(OrderWithNullFK::className(), ['customer_id' => 'id'])->orderBy('created_at');
|
||||||
|
}
|
||||||
|
|
||||||
public function afterSave($insert)
|
public function afterSave($insert)
|
||||||
{
|
{
|
||||||
ActiveRecordTest::$afterSaveInsert = $insert;
|
ActiveRecordTest::$afterSaveInsert = $insert;
|
||||||
|
|||||||
@@ -27,6 +27,14 @@ class Customer extends ActiveRecord
|
|||||||
return $this->hasMany(Order::className(), ['customer_id' => 'id']);
|
return $this->hasMany(Order::className(), ['customer_id' => 'id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \yii\redis\ActiveQuery
|
||||||
|
*/
|
||||||
|
public function getOrdersWithNullFK()
|
||||||
|
{
|
||||||
|
return $this->hasMany(OrderWithNullFK::className(), ['customer_id' => 'id']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
|||||||
24
tests/unit/data/ar/redis/OrderItemWithNullFK.php
Normal file
24
tests/unit/data/ar/redis/OrderItemWithNullFK.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace yiiunit\data\ar\redis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class OrderItem
|
||||||
|
*
|
||||||
|
* @property integer $order_id
|
||||||
|
* @property integer $item_id
|
||||||
|
* @property integer $quantity
|
||||||
|
* @property string $subtotal
|
||||||
|
*/
|
||||||
|
class OrderItemWithNullFK extends ActiveRecord
|
||||||
|
{
|
||||||
|
public static function primaryKey()
|
||||||
|
{
|
||||||
|
return ['order_id', 'item_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attributes()
|
||||||
|
{
|
||||||
|
return ['order_id', 'item_id', 'quantity', 'subtotal'];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
tests/unit/data/ar/redis/OrderWithNullFK.php
Normal file
24
tests/unit/data/ar/redis/OrderWithNullFK.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace yiiunit\data\ar\redis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Order
|
||||||
|
*
|
||||||
|
* @property integer $id
|
||||||
|
* @property integer $customer_id
|
||||||
|
* @property integer $created_at
|
||||||
|
* @property string $total
|
||||||
|
*/
|
||||||
|
class OrderWithNullFK extends ActiveRecord
|
||||||
|
{
|
||||||
|
public static function primaryKey()
|
||||||
|
{
|
||||||
|
return ['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attributes()
|
||||||
|
{
|
||||||
|
return ['id', 'customer_id', 'created_at', 'total'];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -72,7 +72,7 @@ CREATE TABLE "order_item_with_null_fk" (
|
|||||||
order_id INTEGER,
|
order_id INTEGER,
|
||||||
item_id INTEGER,
|
item_id INTEGER,
|
||||||
quantity INTEGER NOT NULL,
|
quantity INTEGER NOT NULL,
|
||||||
subtotal decimal(10,0) NOT NULL,
|
subtotal decimal(10,0) NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE "composite_fk" (
|
CREATE TABLE "composite_fk" (
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ use yiiunit\data\ar\redis\Customer;
|
|||||||
use yiiunit\data\ar\redis\OrderItem;
|
use yiiunit\data\ar\redis\OrderItem;
|
||||||
use yiiunit\data\ar\redis\Order;
|
use yiiunit\data\ar\redis\Order;
|
||||||
use yiiunit\data\ar\redis\Item;
|
use yiiunit\data\ar\redis\Item;
|
||||||
|
use yiiunit\data\ar\redis\OrderItemWithNullFK;
|
||||||
|
use yiiunit\data\ar\redis\OrderWithNullFK;
|
||||||
use yiiunit\framework\ar\ActiveRecordTestTrait;
|
use yiiunit\framework\ar\ActiveRecordTestTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,6 +39,16 @@ class ActiveRecordTest extends RedisTestCase
|
|||||||
return OrderItem::className();
|
return OrderItem::className();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getOrderWithNullFKClass()
|
||||||
|
{
|
||||||
|
return OrderWithNullFK::className();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOrderItemWithNullFKmClass()
|
||||||
|
{
|
||||||
|
return OrderItemWithNullFK::className();
|
||||||
|
}
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|||||||
Reference in New Issue
Block a user