mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Reverted some changes from r84163 because they broke cases where you have two fields of the same name on different subclasses.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84789 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
9e45d960bf
commit
e0e12aeb40
@ -893,9 +893,20 @@ class MySQLQuery extends Query {
|
||||
}
|
||||
|
||||
public function nextRecord() {
|
||||
$data = mysql_fetch_assoc($this->handle);
|
||||
if(!$data) $data = false;
|
||||
return $data;
|
||||
// Coalesce rather than replace common fields.
|
||||
if($data = mysql_fetch_row($this->handle)) {
|
||||
foreach($data as $columnIdx => $value) {
|
||||
$columnName = mysql_field_name($this->handle, $columnIdx);
|
||||
// $value || !$ouput[$columnName] means that the *last* occurring value is shown
|
||||
// !$ouput[$columnName] means that the *first* occurring value is shown
|
||||
if(isset($value) || !isset($output[$columnName])) {
|
||||
$output[$columnName] = $value;
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -739,6 +739,24 @@ class DataObjectTest extends SapphireTest {
|
||||
$this->assertEquals('1988-03-04 06:30:00', $obj->DatetimeField);
|
||||
}
|
||||
|
||||
function testTwoSubclassesWithTheSameFieldNameWork() {
|
||||
// Create two objects of different subclasses, setting the values of fields that are
|
||||
// defined separately in each subclass
|
||||
$obj1 = new DataObjectTest_SubTeam();
|
||||
$obj1->SubclassDatabaseField = "obj1";
|
||||
$obj2 = new OtherSubclassWithSameField();
|
||||
$obj2->SubclassDatabaseField = "obj2";
|
||||
|
||||
// Write them to the database
|
||||
$obj1->write();
|
||||
$obj2->write();
|
||||
|
||||
// Check that the values of those fields are properly read from the database
|
||||
$values = DataObject::get("DataObjectTest_Team", "DataObjectTest_Team.ID IN
|
||||
($obj1->ID, $obj2->ID)")->column("SubclassDatabaseField");
|
||||
$this->assertEquals(array('obj1', 'obj2'), $values);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DataObjectTest_Player extends Member implements TestOnly {
|
||||
@ -805,6 +823,12 @@ class DataObjectTest_SubTeam extends DataObjectTest_Team implements TestOnly {
|
||||
'SubclassDatabaseField' => 'Varchar'
|
||||
);
|
||||
}
|
||||
class OtherSubclassWithSameField extends DataObjectTest_Team {
|
||||
static $db = array(
|
||||
'SubclassDatabaseField' => 'Varchar',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
class DataObjectTest_FieldlessTable extends DataObject implements TestOnly {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user