public function test_caches_column_meta_data()
 {
     Author::first();
     $table_name = Author::table()->get_fully_qualified_table_name(!$this->conn instanceof ActiveRecord\PgsqlAdapter);
     $value = Cache::$adapter->read("get_meta_data-{$table_name}");
     $this->assert_true(is_array($value));
 }
 public function testCachesColumnMetaData()
 {
     Author::first();
     $tableName = Author::table()->getFullyQualifiedTableName(!$this->conn instanceof ActiveRecord\PgsqlAdapter);
     $value = Cache::$adapter->read("get_meta_data-{$tableName}");
     $this->assertTrue(is_array($value));
 }
Example #3
0
 /**
  * @expectedException ActiveRecord\ActiveRecordException
  */
 public function test_delete_with_no_primary_key_defined()
 {
     Author::table()->pk = array();
     $author = author::first();
     $author->delete();
 }
 public function testFindByPkShouldNotUseLimit()
 {
     Author::find(1);
     $this->assertSqlHas('SELECT * FROM authors WHERE author_id=?', Author::table()->lastSql);
 }
 public function test_having()
 {
     $author = Author::first(array('group' => "date(created_at)", 'having' => "created_at > '2009-01-01'"));
     $this->assert_true(strpos(Author::table()->last_sql, "GROUP BY date(created_at) HAVING created_at > '2009-01-01'") !== false);
 }
Example #6
0
 public function test_find_by_pk_should_not_use_limit()
 {
     Author::find(1);
     $this->assert_sql_has('SELECT * FROM authors WHERE author_id=?', Author::table()->last_sql);
 }
 public function test_default_expire()
 {
     $this->assert_equals(30, Author::table()->cache_model_expire);
 }
 public function test_update_all_with_limit_and_order()
 {
     if (!$this->conn->accepts_limit_and_order_for_update_and_delete()) {
         $this->mark_test_skipped('Only MySQL & Sqlite accept limit/order with UPDATE clause');
     }
     $num_affected = Author::update_all(array('set' => 'parent_author_id = 2', 'limit' => 1, 'order' => 'name asc'));
     $this->assert_equals(1, $num_affected);
     $this->assert_true(strpos(Author::table()->last_sql, 'ORDER BY name asc LIMIT 1') !== false);
 }
 public function testUpdateAllWithLimitAndOrder()
 {
     if (!$this->conn->acceptsLimitAndOrderForUpdateAndDelete()) {
         $this->markTestSkipped('Only MySQL & Sqlite accept limit/order with UPDATE clause');
     }
     $numAffected = Author::updateAll(array('set' => 'parent_author_id = 2', 'limit' => 1, 'order' => 'name asc'));
     $this->assertEquals(1, $numAffected);
     $this->assertTrue(strpos(Author::table()->lastSql, 'ORDER BY name asc LIMIT 1') !== false);
 }
 /**
  * @covers ::with()
  */
 public function testWithOptionArray()
 {
     $b = new SelectBuilder();
     $b->root('Article');
     $b->with(['blog', 'author'])->select(['*']);
     $components = $b->build();
     $jc = array(new JoinClause('articles', '_'), (new JoinClause('blogs', 'blog', JoinClause::LEFT))->on('_', 'blog_id', 'blog', 'id'), (new JoinClause('authors', 'author', JoinClause::LEFT))->on('_', 'author_id', 'author', 'id'));
     $columns = array('_' => ['columns' => Article::table()->getColumns(), 'resAlias' => ''], 'blog' => ['columns' => Blog::table()->getColumns(), 'resAlias' => 'blog'], 'author' => ['columns' => Author::table()->getColumns(), 'resAlias' => 'author']);
     $this->assertEquals($jc, $components['from']);
     $this->assertEquals($columns, $components['columns']);
 }
 public function testAddInvolvedTable()
 {
     $b = new WhereBuilder();
     $b->setRootModel('Blog');
     $b->addInvolvedTable('articles.author');
     $this->assertEquals('Article', $b->getInvolvedModel('articles'));
     $this->assertEquals(Article::table(), $b->getInvolvedTable('articles'));
     $jc = (new JoinClause('articles', 'articles'))->on('_', 'id', 'articles', 'blog_id');
     $this->assertEquals($jc, $b->getJoinClause('articles'));
     $this->assertEquals('Author', $b->getInvolvedModel('articles.author'));
     $this->assertEquals(Author::table(), $b->getInvolvedTable('articles.author'));
     $jc = (new JoinClause('authors', 'articles.author'))->on('articles', 'author_id', 'articles.author', 'id');
     $this->assertEquals($jc, $b->getJoinClause('articles.author'));
 }