public function testGroup()
 {
     $venues = Venue::all(array('select' => 'state', 'group' => 'state'));
     $this->assertTrue(count($venues) > 0);
     $this->assertSqlHas('GROUP BY state', ActiveRecord\Table::load('Venue')->lastSql);
 }
 public function test_gh_23_relationships_with_joins_to_same_table_should_alias_table_name()
 {
     $old = Book::$belongs_to;
     Book::$belongs_to = array(array('from_', 'class_name' => 'Author', 'foreign_key' => 'author_id'), array('to', 'class_name' => 'Author', 'foreign_key' => 'secondary_author_id'), array('another', 'class_name' => 'Author', 'foreign_key' => 'secondary_author_id'));
     $c = ActiveRecord\Table::load('Book')->conn;
     $select = "books.*, authors.name as to_author_name, {$c->quote_name('from_')}.name as from_author_name, {$c->quote_name('another')}.name as another_author_name";
     $book = Book::find(2, array('joins' => array('to', 'from_', 'another'), 'select' => $select));
     $this->assert_not_null($book->from_author_name);
     $this->assert_not_null($book->to_author_name);
     $this->assert_not_null($book->another_author_name);
     Book::$belongs_to = $old;
 }
 public function test_clear_cache_for_specific_class()
 {
     $book_table1 = ActiveRecord\Table::load('Book');
     $book_table2 = ActiveRecord\Table::load('Book');
     ActiveRecord\Table::clear_cache('Book');
     $book_table3 = ActiveRecord\Table::load('Book');
     $this->assert_true($book_table1 === $book_table2);
     $this->assert_true($book_table1 !== $book_table3);
 }
 public function test_group_with_order_and_limit_and_having()
 {
     $venues = Venue::all(array('select' => 'state', 'group' => 'state', 'having' => 'length(state) = 2', 'order' => 'state', 'limit' => 2));
     $this->assert_true(count($venues) > 0);
     $this->assert_true(strpos(ActiveRecord\Table::load('Venue')->last_sql, 'GROUP BY state HAVING length(state) = 2 ORDER BY state LIMIT 0,2') !== false);
 }
Beispiel #5
0
 public function test_before_validation_returned_false_halts_execution()
 {
     VenueCB::$before_validation = array('before_validation_halt_execution');
     ActiveRecord\Table::clear_cache('VenueCB');
     $table = ActiveRecord\Table::load('VenueCB');
     $v = VenueCB::find(1);
     $v->name .= 'test';
     $ret = $v->save();
     $this->assert_false($ret);
     $this->assert_true(strpos(ActiveRecord\Table::load('VenueCB')->last_sql, 'UPDATE') === false);
 }
 public function testGh23RelationshipsWithJoinsToSameTableShouldAliasTableName()
 {
     $old = Book::$belongsTo;
     Book::$belongsTo = array(array('from_', 'className' => 'Author', 'foreignKey' => 'author_id'), array('to', 'className' => 'Author', 'foreignKey' => 'secondary_author_id'), array('another', 'className' => 'Author', 'foreignKey' => 'secondary_author_id'));
     $c = ActiveRecord\Table::load('Book')->conn;
     $select = "books.*, authors.name as to_author_name, {$c->quoteName('from_')}.name as from_author_name, {$c->quoteName('another')}.name as another_author_name";
     $book = Book::find(2, array('joins' => array('to', 'from_', 'another'), 'select' => $select));
     $this->assertNotNull($book->from_author_name);
     $this->assertNotNull($book->to_author_name);
     $this->assertNotNull($book->another_author_name);
     Book::$belongsTo = $old;
 }
 public function test_has_many_through_with_conditions()
 {
     Event::$belongs_to = array(array('host'));
     Venue::$has_many[1] = array('hosts', 'through' => 'events', 'conditions' => array('events.title != ?', 'Love Overboard'));
     $venue = $this->get_relationship();
     $this->assert_true(count($venue->hosts) === 1);
     $this->assert_true(strpos(ActiveRecord\Table::load('Host')->last_sql, "events.title !=") !== false);
 }
 public function testClearCacheForSpecificClass()
 {
     $bookTable1 = ActiveRecord\Table::load('Book');
     $bookTable2 = ActiveRecord\Table::load('Book');
     ActiveRecord\Table::clearCache('Book');
     $bookTable3 = ActiveRecord\Table::load('Book');
     $this->assertTrue($bookTable1 === $bookTable2);
     $this->assertTrue($bookTable1 !== $bookTable3);
 }
 public function testBeforeValidationReturnedFalseHaltsExecution()
 {
     VenueCB::$beforeValidation = array('beforeValidationHaltExecution');
     ActiveRecord\Table::clearCache('VenueCB');
     $table = ActiveRecord\Table::load('VenueCB');
     $v = VenueCB::find(1);
     $v->name .= 'test';
     $ret = $v->save();
     $this->assertFalse($ret);
     $this->assertTrue(strpos(ActiveRecord\Table::load('VenueCB')->lastSql, 'UPDATE') === false);
 }