Exemple #1
0
 /**
  * @return \yii\redis\ActiveQuery
  */
 public function getOrdersWithNullFK()
 {
     return $this->hasMany(OrderWithNullFK::className(), ['customer_id' => 'id']);
 }
 public function setUp()
 {
     parent::setUp();
     ActiveRecord::$db = $this->getConnection();
     $customer = new Customer();
     $customer->setAttributes(['email' => '*****@*****.**', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false);
     $customer->save(false);
     $customer = new Customer();
     $customer->setAttributes(['email' => '*****@*****.**', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false);
     $customer->save(false);
     $customer = new Customer();
     $customer->setAttributes(['email' => '*****@*****.**', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false);
     $customer->save(false);
     //		INSERT INTO category (name) VALUES ('Books');
     //		INSERT INTO category (name) VALUES ('Movies');
     $item = new Item();
     $item->setAttributes(['name' => 'Agile Web Application Development with Yii1.1 and PHP5', 'category_id' => 1], false);
     $item->save(false);
     $item = new Item();
     $item->setAttributes(['name' => 'Yii 1.1 Application Development Cookbook', 'category_id' => 1], false);
     $item->save(false);
     $item = new Item();
     $item->setAttributes(['name' => 'Ice Age', 'category_id' => 2], false);
     $item->save(false);
     $item = new Item();
     $item->setAttributes(['name' => 'Toy Story', 'category_id' => 2], false);
     $item->save(false);
     $item = new Item();
     $item->setAttributes(['name' => 'Cars', 'category_id' => 2], false);
     $item->save(false);
     $order = new Order();
     $order->setAttributes(['customer_id' => 1, 'created_at' => 1325282384, 'total' => 110.0], false);
     $order->save(false);
     $order = new Order();
     $order->setAttributes(['customer_id' => 2, 'created_at' => 1325334482, 'total' => 33.0], false);
     $order->save(false);
     $order = new Order();
     $order->setAttributes(['customer_id' => 2, 'created_at' => 1325502201, 'total' => 40.0], false);
     $order->save(false);
     $orderItem = new OrderItem();
     $orderItem->setAttributes(['order_id' => 1, 'item_id' => 1, 'quantity' => 1, 'subtotal' => 30.0], false);
     $orderItem->save(false);
     $orderItem = new OrderItem();
     $orderItem->setAttributes(['order_id' => 1, 'item_id' => 2, 'quantity' => 2, 'subtotal' => 40.0], false);
     $orderItem->save(false);
     $orderItem = new OrderItem();
     $orderItem->setAttributes(['order_id' => 2, 'item_id' => 4, 'quantity' => 1, 'subtotal' => 10.0], false);
     $orderItem->save(false);
     $orderItem = new OrderItem();
     $orderItem->setAttributes(['order_id' => 2, 'item_id' => 5, 'quantity' => 1, 'subtotal' => 15.0], false);
     $orderItem->save(false);
     $orderItem = new OrderItem();
     $orderItem->setAttributes(['order_id' => 2, 'item_id' => 3, 'quantity' => 1, 'subtotal' => 8.0], false);
     $orderItem->save(false);
     $orderItem = new OrderItem();
     $orderItem->setAttributes(['order_id' => 3, 'item_id' => 2, 'quantity' => 1, 'subtotal' => 40.0], false);
     $orderItem->save(false);
     $order = new OrderWithNullFK();
     $order->setAttributes(['customer_id' => 1, 'created_at' => 1325282384, 'total' => 110.0], false);
     $order->save(false);
     $order = new OrderWithNullFK();
     $order->setAttributes(['customer_id' => 2, 'created_at' => 1325334482, 'total' => 33.0], false);
     $order->save(false);
     $order = new OrderWithNullFK();
     $order->setAttributes(['customer_id' => 2, 'created_at' => 1325502201, 'total' => 40.0], false);
     $order->save(false);
     $orderItem = new OrderItemWithNullFK();
     $orderItem->setAttributes(['order_id' => 1, 'item_id' => 1, 'quantity' => 1, 'subtotal' => 30.0], false);
     $orderItem->save(false);
     $orderItem = new OrderItemWithNullFK();
     $orderItem->setAttributes(['order_id' => 1, 'item_id' => 2, 'quantity' => 2, 'subtotal' => 40.0], false);
     $orderItem->save(false);
     $orderItem = new OrderItemWithNullFK();
     $orderItem->setAttributes(['order_id' => 2, 'item_id' => 4, 'quantity' => 1, 'subtotal' => 10.0], false);
     $orderItem->save(false);
     $orderItem = new OrderItemWithNullFK();
     $orderItem->setAttributes(['order_id' => 2, 'item_id' => 5, 'quantity' => 1, 'subtotal' => 15.0], false);
     $orderItem->save(false);
     $orderItem = new OrderItemWithNullFK();
     $orderItem->setAttributes(['order_id' => 2, 'item_id' => 3, 'quantity' => 1, 'subtotal' => 8.0], false);
     $orderItem->save(false);
     $orderItem = new OrderItemWithNullFK();
     $orderItem->setAttributes(['order_id' => 3, 'item_id' => 2, 'quantity' => 1, 'subtotal' => 40.0], false);
     $orderItem->save(false);
 }