Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Possible bug in DataObject::get_one

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

Page: 1
Go to End
Author Topic: 1212 Views
  • zard
    Avatar
    Community Member
    23 Posts

    Possible bug in DataObject::get_one Link to this post

    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

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: Possible bug in DataObject::get_one Link to this post

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

  • mark_s
    Avatar
    Community Member
    78 Posts

    Re: Possible bug in DataObject::get_one Link to this post

    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

    1212 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.