public function testInit() { $this->assertEquals(5, Product::objects()->count()); $this->assertEquals(1, Category::objects()->count()); $this->assertEquals(1, User::objects()->count()); $this->assertEquals(1, Customer::objects()->count()); $this->assertEquals(1, Order::objects()->count()); $this->assertEquals(5, Order::objects()->get(['pk' => 1])->products->count()); $this->assertEquals(1, ProductList::objects()->count()); }
public function testIssue64() { $this->assertEquals(1, Category::objects()->count()); $this->assertEquals(2, Product::objects()->count()); $this->assertEquals(2, ProductList::objects()->count()); $category = Category::objects()->get(); $this->assertEquals(2, $category->products->count()); $this->assertEquals(1, $category->products->filter(['name' => 'bar'])->count()); $this->assertEquals(2, $category->products->filter(['lists__name' => 'test'])->count()); $this->assertEquals(1, $category->products->filter(['lists__name' => 'asd'])->count()); $this->assertEquals("SELECT `tests_product_1`.* FROM `tests_product` `tests_product_1` LEFT OUTER JOIN `tests_product_tests_product_list` `tests_product_tests_product_list_2` ON `tests_product_1`.`id` = `tests_product_tests_product_list_2`.`product_id` LEFT OUTER JOIN `tests_product_list` `tests_product_list_3` ON `tests_product_tests_product_list_2`.`product_list_id` = `tests_product_list_3`.`id` WHERE ((`tests_product_1`.`category_id`='1')) AND ((`tests_product_list_3`.`name`='asd')) GROUP BY `tests_product_1`.`id`", $category->products->filter(['lists__name' => 'asd'])->allSql()); }
public function testIssue79() { $c = Category::objects()->batch(2); foreach ($c as $categories) { $this->assertEquals(2, count($categories)); } $sql = Category::objects()->filter(['pk__in' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]])->allSql(); $this->assertTrue(is_string($sql)); $this->assertEquals($sql, 'SELECT `tests_category_1`.* FROM `tests_category` `tests_category_1` WHERE (`tests_category_1`.`id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10))'); $c = Category::objects()->filter(['pk__in' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]])->batch(2); foreach ($c as $categories) { $this->assertEquals(2, count($categories)); } $c = Category::objects()->filter(['pk__in' => [1, 2, 3, 4]])->batch(2); $total = 0; foreach ($c as $categories) { $total += count($categories); $this->assertEquals(2, count($categories)); } $this->assertEquals(4, $total); }
public function testExclude() { $this->assertEquals(1, count(Category::objects()->exclude(['name' => 'one'])->all())); }