refactored ActiveRecord::unlinkAll() to work will noSQL

issue #3520
This commit is contained in:
Carsten Brandt
2014-06-04 14:28:57 +02:00
parent 274b6e41b4
commit d92281dcda
9 changed files with 230 additions and 100 deletions

View File

@@ -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
]
]
]);
}
}

View File

@@ -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';
}
}

View File

@@ -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';
}
}