mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-09 01:27:20 +08:00
Sphinx Active Record saving via 'replace' converted into fallback
This commit is contained in:
@ -851,7 +851,20 @@ class ActiveRecord extends Model
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace is supported only by runtime indexes and necessary only for field update
|
||||||
|
$useReplace = false;
|
||||||
|
$indexSchema = $this->getIndexSchema();
|
||||||
if ($this->getIndexSchema()->isRuntime) {
|
if ($this->getIndexSchema()->isRuntime) {
|
||||||
|
foreach ($values as $name => $value) {
|
||||||
|
$columnSchema = $indexSchema->getColumn($name);
|
||||||
|
if ($columnSchema->isField) {
|
||||||
|
$useReplace = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($useReplace) {
|
||||||
$values = array_merge($values, $this->getOldPrimaryKey(true));
|
$values = array_merge($values, $this->getOldPrimaryKey(true));
|
||||||
$command = static::getDb()->createCommand();
|
$command = static::getDb()->createCommand();
|
||||||
$command->replace(static::indexName(), $values);
|
$command->replace(static::indexName(), $values);
|
||||||
|
|||||||
@ -161,6 +161,16 @@ class ActiveRecordTest extends SphinxTestCase
|
|||||||
$record2 = RuntimeIndex::find(['id' => 2]);
|
$record2 = RuntimeIndex::find(['id' => 2]);
|
||||||
$this->assertEquals(9, $record2->type_id);
|
$this->assertEquals(9, $record2->type_id);
|
||||||
|
|
||||||
|
// replace
|
||||||
|
$query = 'replace';
|
||||||
|
$rows = RuntimeIndex::find($query);
|
||||||
|
$this->assertEmpty($rows);
|
||||||
|
$record = RuntimeIndex::find(['id' => 2]);
|
||||||
|
$record->content = 'Test content with ' . $query;
|
||||||
|
$record->save();
|
||||||
|
$rows = RuntimeIndex::find($query);
|
||||||
|
$this->assertNotEmpty($rows);
|
||||||
|
|
||||||
// updateAll
|
// updateAll
|
||||||
$pk = ['id' => 2];
|
$pk = ['id' => 2];
|
||||||
$ret = RuntimeIndex::updateAll(['type_id' => 55], $pk);
|
$ret = RuntimeIndex::updateAll(['type_id' => 55], $pk);
|
||||||
|
|||||||
Reference in New Issue
Block a user