Esempio n. 1
0
 public function setUp()
 {
     parent::setUp();
     /* @var $db Connection */
     $db = ActiveRecord::$db = $this->getConnection();
     // delete index
     if ($db->createCommand()->indexExists('yiitest')) {
         $db->createCommand()->deleteIndex('yiitest');
     }
     $db->createCommand()->createIndex('yiitest');
     $command = $db->createCommand();
     Customer::setUpMapping($command);
     Item::setUpMapping($command);
     Order::setUpMapping($command);
     OrderItem::setUpMapping($command);
     OrderWithNullFK::setUpMapping($command);
     OrderItemWithNullFK::setUpMapping($command);
     $db->createCommand()->flushIndex('yiitest');
     $customer = new Customer();
     $customer->id = 1;
     $customer->setAttributes(['email' => '*****@*****.**', 'name' => 'user1', 'address' => 'address1', 'status' => 1], false);
     $customer->save(false);
     $customer = new Customer();
     $customer->id = 2;
     $customer->setAttributes(['email' => '*****@*****.**', 'name' => 'user2', 'address' => 'address2', 'status' => 1], false);
     $customer->save(false);
     $customer = new Customer();
     $customer->id = 3;
     $customer->setAttributes(['email' => '*****@*****.**', 'name' => 'user3', 'address' => 'address3', 'status' => 2], false);
     $customer->save(false);
     //		INSERT INTO category (name) VALUES ('Books');
     //		INSERT INTO category (name) VALUES ('Movies');
     $item = new Item();
     $item->id = 1;
     $item->setAttributes(['name' => 'Agile Web Application Development with Yii1.1 and PHP5', 'category_id' => 1], false);
     $item->save(false);
     $item = new Item();
     $item->id = 2;
     $item->setAttributes(['name' => 'Yii 1.1 Application Development Cookbook', 'category_id' => 1], false);
     $item->save(false);
     $item = new Item();
     $item->id = 3;
     $item->setAttributes(['name' => 'Ice Age', 'category_id' => 2], false);
     $item->save(false);
     $item = new Item();
     $item->id = 4;
     $item->setAttributes(['name' => 'Toy Story', 'category_id' => 2], false);
     $item->save(false);
     $item = new Item();
     $item->id = 5;
     $item->setAttributes(['name' => 'Cars', 'category_id' => 2], false);
     $item->save(false);
     $order = new Order();
     $order->id = 1;
     $order->setAttributes(['customer_id' => 1, 'created_at' => 1325282384, 'total' => 110.0, 'itemsArray' => [1, 2]], false);
     $order->save(false);
     $order = new Order();
     $order->id = 2;
     $order->setAttributes(['customer_id' => 2, 'created_at' => 1325334482, 'total' => 33.0, 'itemsArray' => [4, 5, 3]], false);
     $order->save(false);
     $order = new Order();
     $order->id = 3;
     $order->setAttributes(['customer_id' => 2, 'created_at' => 1325502201, 'total' => 40.0, 'itemsArray' => [2]], 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->id = 1;
     $order->setAttributes(['customer_id' => 1, 'created_at' => 1325282384, 'total' => 110.0], false);
     $order->save(false);
     $order = new OrderWithNullFK();
     $order->id = 2;
     $order->setAttributes(['customer_id' => 2, 'created_at' => 1325334482, 'total' => 33.0], false);
     $order->save(false);
     $order = new OrderWithNullFK();
     $order->id = 3;
     $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);
     $db->createCommand()->flushIndex('yiitest');
 }