exists() public static method

public static exists ( ModelQueryBuilder $queryBuilder )
$queryBuilder Ouzo\Db\ModelQueryBuilder
Beispiel #1
0
 /**
  * @test
  */
 public function shouldBuildExistsClause()
 {
     // when
     $result = WhereClause::exists(Product::where(array('name' => 'phone')));
     // then
     $this->assertEquals(array('phone'), $result->getParameters());
     Assert::thatString($result->toSql())->startsWith('EXISTS (SELECT')->endsWith('FROM products WHERE name = ?)');
 }
 /**
  * @test
  */
 public function shouldFindWhereExists()
 {
     //given
     Product::create(array('name' => 'other'));
     $product = Product::create(array('name' => 'phones'));
     $order = Order::create(array('name' => 'a'));
     OrderProduct::create(array('id_order' => $order->getId(), 'id_product' => $product->getId()));
     //when
     $products = Product::where(WhereClause::exists(OrderProduct::where('id_product = products.id')))->fetchAll();
     //then
     $this->assertCount(1, $products);
     $this->assertEquals($product->getId(), $products[0]->getId());
 }