Browse Source

Sphinx Active Record saving via 'replace' converted into fallback

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
bd79e1c1be
  1. 13
      extensions/sphinx/ActiveRecord.php
  2. 10
      tests/unit/extensions/sphinx/ActiveRecordTest.php

13
extensions/sphinx/ActiveRecord.php

@ -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);

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

@ -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);

Loading…
Cancel
Save