Browse Source

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

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
3db7a07534
  1. 27
      extensions/sphinx/ActiveRecord.php
  2. 9
      tests/unit/extensions/sphinx/ActiveRecordTest.php

27
extensions/sphinx/ActiveRecord.php

@ -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.
*
* Note that because the SQL statement is already specified, calling additional

9
tests/unit/extensions/sphinx/ActiveRecordTest.php

@ -41,10 +41,9 @@ class ActiveRecordTest extends SphinxTestCase
$this->assertTrue($articles[1] instanceof ArticleIndex);
// find fulltext
$articles = ArticleIndex::find('cats');
$this->assertEquals(1, count($articles));
$this->assertTrue($articles[0] instanceof ArticleIndex);
$this->assertEquals(1, $articles[0]->id);
$article = ArticleIndex::find(2);
$this->assertTrue($article instanceof ArticleIndex);
$this->assertEquals(2, $article->id);
// find by column values
$article = ArticleIndex::find(['id' => 2, 'author_id' => 2]);
@ -168,7 +167,7 @@ class ActiveRecordTest extends SphinxTestCase
$record = RuntimeIndex::find(['id' => 2]);
$record->content = 'Test content with ' . $query;
$record->save();
$rows = RuntimeIndex::find($query);
$rows = RuntimeIndex::find()->match($query);
$this->assertNotEmpty($rows);
// updateAll

Loading…
Cancel
Save