Browse Source

Composite primary key support removed from Sphinx schema.

tags/2.0.0-beta
Klimov Paul 11 years ago
parent
commit
9459b44022
  1. 27
      extensions/sphinx/IndexSchema.php
  2. 8
      extensions/sphinx/Schema.php

27
extensions/sphinx/IndexSchema.php

@ -29,9 +29,9 @@ class IndexSchema extends Object
*/
public $name;
/**
* @var string[] primary keys of this index.
* @var string primary key of this index.
*/
public $primaryKey = [];
public $primaryKey;
/**
* @var ColumnSchema[] column metadata of this index. Each array element is a [[ColumnSchema]] object, indexed by column names.
*/
@ -56,27 +56,4 @@ class IndexSchema extends Object
{
return array_keys($this->columns);
}
/**
* Manually specifies the primary key for this table.
* @param string|array $keys the primary key (can be composite)
* @throws InvalidParamException if the specified key cannot be found in the table.
*/
public function fixPrimaryKey($keys)
{
if (!is_array($keys)) {
$keys = [$keys];
}
$this->primaryKey = $keys;
foreach ($this->columns as $column) {
$column->isPrimaryKey = false;
}
foreach ($keys as $key) {
if (isset($this->columns[$key])) {
$this->columns[$key]->isPrimaryKey = true;
} else {
throw new InvalidParamException("Primary key '$key' cannot be found in index '{$this->name}'.");
}
}
}
}

8
extensions/sphinx/Schema.php

@ -70,7 +70,7 @@ class Schema extends Object
* @param string $name index name
* @return IndexSchema driver dependent index metadata. Null if the index does not exist.
*/
protected function loadTableSchema($name)
protected function loadIndexSchema($name)
{
$index = new IndexSchema;
$this->resolveIndexNames($index, $name);
@ -119,7 +119,7 @@ class Schema extends Object
if ($cache instanceof Cache) {
$key = $this->getCacheKey($name);
if ($refresh || ($index = $cache->get($key)) === false) {
$index = $this->loadTableSchema($realName);
$index = $this->loadIndexSchema($realName);
if ($index !== null) {
$cache->set($key, $index, $db->schemaCacheDuration, new GroupDependency($this->getCacheGroup()));
}
@ -127,7 +127,7 @@ class Schema extends Object
return $this->_indexes[$name] = $index;
}
}
return $this->_indexes[$name] = $index = $this->loadTableSchema($realName);
return $this->_indexes[$name] = $index = $this->loadIndexSchema($realName);
}
/**
@ -424,7 +424,7 @@ class Schema extends Object
$column = $this->loadColumnSchema($info);
$index->columns[$column->name] = $column;
if ($column->isPrimaryKey) {
$index->primaryKey[] = $column->name;
$index->primaryKey = $column->name;
}
}
return true;

Loading…
Cancel
Save