mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
parent
ed013fcfbb
commit
d1396b7dfe
@ -1413,8 +1413,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
// Inserts done one the base table are performed in another step, so the manipulation should instead
|
// Inserts done one the base table are performed in another step, so the manipulation should instead
|
||||||
// attempt an update, as though it were a normal update.
|
// attempt an update, as though it were a normal update.
|
||||||
$manipulation[$table]['command'] = $isNewRecord ? 'insert' : 'update';
|
$manipulation[$table]['command'] = $isNewRecord ? 'insert' : 'update';
|
||||||
$manipulation[$table]['id'] = $this->record['ID'];
|
|
||||||
$manipulation[$table]['class'] = $class;
|
$manipulation[$table]['class'] = $class;
|
||||||
|
if ($this->isInDB()) {
|
||||||
|
$manipulation[$table]['id'] = $this->record['ID'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1433,10 +1435,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform an insert on the base table
|
// Perform an insert on the base table
|
||||||
$insert = new SQLInsert('"' . $baseTable . '"');
|
$manipulation = [];
|
||||||
$insert
|
$this->prepareManipulationTable($baseTable, $now, true, $manipulation, $this->baseClass());
|
||||||
->assign('"Created"', $now)
|
DB::manipulate($manipulation);
|
||||||
->execute();
|
|
||||||
$this->changed['ID'] = self::CHANGE_VALUE;
|
$this->changed['ID'] = self::CHANGE_VALUE;
|
||||||
$this->record['ID'] = DB::get_generated_id($baseTable);
|
$this->record['ID'] = DB::get_generated_id($baseTable);
|
||||||
}
|
}
|
||||||
|
@ -343,4 +343,35 @@ class DataObjectSchemaTest extends SapphireTest
|
|||||||
'columns' => ['IndexedMoneyCurrency', 'IndexedMoneyAmount']
|
'columns' => ['IndexedMoneyCurrency', 'IndexedMoneyAmount']
|
||||||
], $indexes['IndexedMoney']);
|
], $indexes['IndexedMoney']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that records with unique indexes can be written
|
||||||
|
*/
|
||||||
|
public function testWriteUniqueIndexes()
|
||||||
|
{
|
||||||
|
// Create default object
|
||||||
|
$zeroObject = new AllIndexes();
|
||||||
|
$zeroObject->Number = 0;
|
||||||
|
$zeroObject->write();
|
||||||
|
|
||||||
|
$this->assertListEquals(
|
||||||
|
[
|
||||||
|
['Number' => 0],
|
||||||
|
],
|
||||||
|
AllIndexes::get()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test a new record can be created without clashing with default value
|
||||||
|
$validObject = new AllIndexes();
|
||||||
|
$validObject->Number = 1;
|
||||||
|
$validObject->write();
|
||||||
|
|
||||||
|
$this->assertListEquals(
|
||||||
|
[
|
||||||
|
['Number' => 0],
|
||||||
|
['Number' => 1],
|
||||||
|
],
|
||||||
|
AllIndexes::get()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,11 @@ use SilverStripe\Dev\TestOnly;
|
|||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\FieldType\DBIndexable;
|
use SilverStripe\ORM\FieldType\DBIndexable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $Number
|
||||||
|
* @property string $Content
|
||||||
|
* @property string $Title
|
||||||
|
*/
|
||||||
class AllIndexes extends DataObject implements TestOnly
|
class AllIndexes extends DataObject implements TestOnly
|
||||||
{
|
{
|
||||||
private static $table_name = 'DataObjectSchemaTest_AllIndexes';
|
private static $table_name = 'DataObjectSchemaTest_AllIndexes';
|
||||||
|
Loading…
Reference in New Issue
Block a user