コード例 #1
0
ファイル: ActiveRecordTest.php プロジェクト: aivavic/yii2
 public function testFindBySql()
 {
     // find one
     $article = ArticleIndex::findBySql('SELECT * FROM yii2_test_article_index ORDER BY id DESC')->one();
     $this->assertTrue($article instanceof ArticleIndex);
     $this->assertEquals(2, $article->author_id);
     // find all
     $articles = ArticleIndex::findBySql('SELECT * FROM yii2_test_article_index')->all();
     $this->assertEquals(2, count($articles));
     // find with parameter binding
     $article = ArticleIndex::findBySql('SELECT * FROM yii2_test_article_index WHERE id=:id', [':id' => 2])->one();
     $this->assertTrue($article instanceof ArticleIndex);
     $this->assertEquals(2, $article->author_id);
 }