Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

FIX Recent patch to DataObject#db changed API which broke core

  • Loading branch information...
commit ca63e33c194e2a880ba7d2ef659333b0da0bc0e0 1 parent a862b4d
@hafriedlander hafriedlander authored
Showing with 14 additions and 9 deletions.
  1. +3 −9 model/DataObject.php
  2. +11 −0 tests/model/DataObjectTest.php
View
12 model/DataObject.php
@@ -1661,16 +1661,11 @@ public function belongs_to($component = null, $classOnly = true) {
/**
* Return all of the database fields defined in self::$db and all the parent classes.
* Doesn't include any fields specified by self::$has_one. Use $this->has_one() to get these fields
- * Also returns "base" fields like "Created", "LastEdited", et cetera.
*
* @param string $fieldName Limit the output to a specific field name
* @return array The database fields
*/
public function db($fieldName = null) {
- if ($fieldName && array_key_exists($fieldName, self::$fixed_fields)) {
- return self::$fixed_fields[$fieldName];
- }
-
$classes = ClassInfo::ancestry($this);
$good = false;
$items = array();
@@ -1709,10 +1704,6 @@ public function db($fieldName = null) {
}
}
- if (!$fieldName) {
- // trying to get all fields, so add the fixed fields to return value
- $items = array_merge(self::$fixed_fields, $items);
- }
return $items;
}
@@ -2675,6 +2666,9 @@ public function dbObject($fieldName) {
$val = get_class($this);
return DBField::create_field('Varchar', $val, $fieldName, $this);
+ } else if(array_key_exists($fieldName, self::$fixed_fields)) {
+ return DBField::create_field(self::$fixed_fields[$fieldName], $this->$fieldName, $fieldName, $this);
+
// General casting information for items in $db
} else if($helper = $this->db($fieldName)) {
$obj = Object::create_from_string($helper, $fieldName);
View
11 tests/model/DataObjectTest.php
@@ -19,6 +19,17 @@ class DataObjectTest extends SapphireTest {
'DataObjectTest_TeamComment'
);
+ public function testBaseFieldsExcludedFromDb() {
+ $obj = new DataObjectTest_ValidatedObject();
+
+ $dbFields = $obj->db();
+ $this->assertArrayHasKey('Name', $dbFields);
+ $this->assertArrayNotHasKey('Created', $dbFields);
+ $this->assertArrayNotHasKey('LastEdited', $dbFields);
+ $this->assertArrayNotHasKey('ClassName', $dbFields);
+ $this->assertArrayNotHasKey('ID', $dbFields);
+ }
+
public function testValidObjectsForBaseFields() {
$obj = new DataObjectTest_ValidatedObject();
Please sign in to comment.
Something went wrong with that request. Please try again.