Commit bd79e1c1 by Paul Klimov

Sphinx Active Record saving via 'replace' converted into fallback

parent cd3950aa
......@@ -851,7 +851,20 @@ class ActiveRecord extends Model
return 0;
}
// Replace is supported only by runtime indexes and necessary only for field update
$useReplace = false;
$indexSchema = $this->getIndexSchema();
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));
$command = static::getDb()->createCommand();
$command->replace(static::indexName(), $values);
......
......@@ -161,6 +161,16 @@ class ActiveRecordTest extends SphinxTestCase
$record2 = RuntimeIndex::find(['id' => 2]);
$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
$pk = ['id' => 2];
$ret = RuntimeIndex::updateAll(['type_id' => 55], $pk);
......
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