Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Possible bug in DataObject::get_one


Go to End


3 Posts   1783 Views

Avatar
zard

Community Member, 25 Posts

1 July 2010 at 8:29am

Edited: 01/07/2010 8:30am

Hi,
I am quite new to SS but I do believe that this time the problem is not completely in me.

I am trying to get a record from the database and load it into an object, the syntax looks like this:

if ($confirmKey = DataObject::get_one("ConfirmationCode", "ID = ".$member->ConfirmCodeID)) {
//confirmation is found, try to output it's data!
die(print_r($confirmKey, true));
else {
not found error message
}

The code actually goes to the first branch (which I believe means that the record is located) but the $confirmKey only contains empty/brand new ConfirmationCode object!
Output of that die method yields this:
ConfirmationCode Object ( 
 [destroyed] => 
 [record:protected] => Array ( 
   [ID] => 0 [ClassName] => ConfirmationCode 
   [RecordClassName] => ConfirmationCode 
  ) 
  [changed:DataObject:private] => Array ( ) 
  [original:protected] => Array ( [ID] => 0 
  [ClassName] => ConfirmationCode 
  [RecordClassName] => ConfirmationCode ) 
  [components:protected] => 
  [brokenOnDelete:protected] => 
  [brokenOnWrite:protected] => 
  [componentCache:protected] => 
  [iteratorPos:protected] => 
  [iteratorTotalItems:protected] => 
  [failover:protected] => 
  [customisedObject:protected] => 
  [objCache:ViewableData:private] => Array ( ) 
  [class] => ConfirmationCode [extension_instances:protected] => Array ( ) 
) 

What is the problem? I am getting desperate... same result when using get_by_id

Avatar
baba-papa

Community Member, 279 Posts

11 July 2010 at 9:06pm

Did you check the database table if the properties are set?

Avatar
mark_s

Community Member, 78 Posts

13 July 2010 at 9:24am

Hi.

Can you pass false to the third parameter of DataObject::get_one and see if that makes any difference? This will prevent get_one from using its cache, and force load from the database.

Mark