FIX: Fix DataObject::get_one() when the classname is passed with improper casing.

This commit is contained in:
Sam Minnee 2013-01-11 12:20:28 +13:00
parent e8bfc241fd
commit f4efaeefa7
2 changed files with 6 additions and 4 deletions

View File

@ -2850,12 +2850,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
&& DataObject::$_cache_get_one[$callerClass][$cacheKey] instanceof DataObject && DataObject::$_cache_get_one[$callerClass][$cacheKey] instanceof DataObject
&& DataObject::$_cache_get_one[$callerClass][$cacheKey]->destroyed) { && DataObject::$_cache_get_one[$callerClass][$cacheKey]->destroyed) {
DataObject::$_cache_get_one[$callerClass][$cacheKey DataObject::$_cache_get_one[$callerClass][$cacheKey] = false;
] = false;
} }
if(!$cache || !isset(DataObject::$_cache_get_one[$callerClass][$cacheKey])) { if(!$cache || !isset(DataObject::$_cache_get_one[$callerClass][$cacheKey])) {
$dl = DataList::create($callerClass)->where($filter)->sort($orderby); $dl = $callerClass::get()->where($filter)->sort($orderby);
$dl->setDataModel(DataModel::inst());
$item = $dl->First(); $item = $dl->First();
if($cache) { if($cache) {

View File

@ -171,6 +171,10 @@ class DataObjectTest extends SapphireTest {
$this->assertEquals('Bob', $comment->Name); $this->assertEquals('Bob', $comment->Name);
$comment = DataObject::get_one('DataObjectTest_TeamComment', '', true, '"Name" DESC'); $comment = DataObject::get_one('DataObjectTest_TeamComment', '', true, '"Name" DESC');
$this->assertEquals('Phil', $comment->Name); $this->assertEquals('Phil', $comment->Name);
// Test get_one() with bad case on the classname
$subteam1 = DataObject::get_one('dataobjecttest_subteam', "\"Title\" = 'Subteam 1'", true);
$this->assertEquals($subteam1->Title, "Subteam 1");
} }
public function testGetSubclassFields() { public function testGetSubclassFields() {