Commit 3db7a075 by Paul Klimov

Method "yii\sphinx\ActiveRecord::find()" removed in favour of "BaseActiveRecord::find()".

parent c9624eee
...@@ -79,33 +79,6 @@ abstract class ActiveRecord extends BaseActiveRecord ...@@ -79,33 +79,6 @@ abstract class ActiveRecord extends BaseActiveRecord
} }
/** /**
* Creates an [[ActiveQuery]] instance for query purpose.
*
* @param mixed $q the query parameter. This can be one of the followings:
*
* - a string: fulltext query by a query string and return the list
* of matching records.
* - an array of name-value pairs: query by a set of column values and return a single record matching all of them.
* - null: return a new [[ActiveQuery]] object for further query purpose.
*
* @return ActiveQuery|ActiveRecord[]|ActiveRecord|null When `$q` is null, a new [[ActiveQuery]] instance
* is returned; when `$q` is a string, an array of ActiveRecord objects matching it will be returned;
* when `$q` is an array, an ActiveRecord object matching it will be returned (null
* will be returned if there is no matching).
* @see createQuery()
*/
public static function find($q = null)
{
$query = static::createQuery();
if (is_array($q)) {
return $query->where($q)->one();
} elseif ($q !== null) {
return $query->match($q)->all();
}
return $query;
}
/**
* Creates an [[ActiveQuery]] instance with a given SQL statement. * Creates an [[ActiveQuery]] instance with a given SQL statement.
* *
* Note that because the SQL statement is already specified, calling additional * Note that because the SQL statement is already specified, calling additional
......
...@@ -41,10 +41,9 @@ class ActiveRecordTest extends SphinxTestCase ...@@ -41,10 +41,9 @@ class ActiveRecordTest extends SphinxTestCase
$this->assertTrue($articles[1] instanceof ArticleIndex); $this->assertTrue($articles[1] instanceof ArticleIndex);
// find fulltext // find fulltext
$articles = ArticleIndex::find('cats'); $article = ArticleIndex::find(2);
$this->assertEquals(1, count($articles)); $this->assertTrue($article instanceof ArticleIndex);
$this->assertTrue($articles[0] instanceof ArticleIndex); $this->assertEquals(2, $article->id);
$this->assertEquals(1, $articles[0]->id);
// find by column values // find by column values
$article = ArticleIndex::find(['id' => 2, 'author_id' => 2]); $article = ArticleIndex::find(['id' => 2, 'author_id' => 2]);
...@@ -168,7 +167,7 @@ class ActiveRecordTest extends SphinxTestCase ...@@ -168,7 +167,7 @@ class ActiveRecordTest extends SphinxTestCase
$record = RuntimeIndex::find(['id' => 2]); $record = RuntimeIndex::find(['id' => 2]);
$record->content = 'Test content with ' . $query; $record->content = 'Test content with ' . $query;
$record->save(); $record->save();
$rows = RuntimeIndex::find($query); $rows = RuntimeIndex::find()->match($query);
$this->assertNotEmpty($rows); $this->assertNotEmpty($rows);
// updateAll // updateAll
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment