conditions() public method

Results of this method are stored in a memory cache. This improves performance, but because the method uses a hashing algorithm it can have collisions. Setting DboSource::$cacheMethods to false will disable the memory cache.
public conditions ( mixed $conditions, boolean $quoteValues = true, boolean $where = true, Model $Model = null ) : string
$conditions mixed Array or string of conditions, or any value.
$quoteValues boolean If true, values should be quoted
$where boolean If true, "WHERE " will be prepended to the return value
$Model Model A reference to the Model instance making the query
return string SQL fragment
 /**
  * test a full example of using virtual fields
  *
  * @return void
  */
 public function testVirtualFieldsFetch()
 {
     $this->loadFixtures('Article', 'Comment');
     $Article = ClassRegistry::init('Article');
     $Article->virtualFields = array('comment_count' => 'SELECT COUNT(*) FROM ' . $this->Dbo->fullTableName('comments') . ' WHERE Article.id = ' . $this->Dbo->fullTableName('comments') . '.article_id');
     $conditions = array('comment_count >' => 2);
     $query = 'SELECT ' . join(',', $this->Dbo->fields($Article, null, array('id', 'comment_count'))) . ' FROM ' . $this->Dbo->fullTableName($Article) . ' Article ' . $this->Dbo->conditions($conditions, true, true, $Article);
     $result = $this->Dbo->fetchAll($query);
     $expected = array(array('Article' => array('id' => 1, 'comment_count' => 4)));
     $this->assertEquals($expected, $result);
 }
 /**
  * Tests passing PostgreSQL regular expression operators when building queries
  *
  * @return void
  */
 public function testRegexpOperatorConditionsParsing()
 {
     $this->assertSame(' WHERE "name" ~ \'[a-z_]+\'', $this->Dbo->conditions(array('name ~' => '[a-z_]+')));
     $this->assertSame(' WHERE "name" ~* \'[a-z_]+\'', $this->Dbo->conditions(array('name ~*' => '[a-z_]+')));
     $this->assertSame(' WHERE "name" !~ \'[a-z_]+\'', $this->Dbo->conditions(array('name !~' => '[a-z_]+')));
     $this->assertSame(' WHERE "name" !~* \'[a-z_]+\'', $this->Dbo->conditions(array('name !~*' => '[a-z_]+')));
 }
Beispiel #3
0
 /**
  * Tests passing PostgreSQL regular expression operators when building queries
  *
  * @return void
  */
 public function testRegexpOperatorConditionsParsing()
 {
     $this->assertSame(' WHERE "name" ~ \'[a-z_]+\'', $this->Dbo->conditions(array('name ~' => '[a-z_]+')));
     $this->assertSame(' WHERE "name" ~* \'[a-z_]+\'', $this->Dbo->conditions(array('name ~*' => '[a-z_]+')));
     $this->assertSame(' WHERE "name" !~ \'[a-z_]+\'', $this->Dbo->conditions(array('name !~' => '[a-z_]+')));
     $this->assertSame(' WHERE "name" !~* \'[a-z_]+\'', $this->Dbo->conditions(array('name !~*' => '[a-z_]+')));
     $this->assertSame(' WHERE EXTRACT( \'YEAR\' FROM "User"."birthday" ) = 2015', $this->Dbo->conditions(array('EXTRACT( \'YEAR\' FROM User.birthday )' => 2015)));
 }