Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » ID of an entry in the DB before write()?

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

Page: 1
Go to End
Author Topic: 1551 Views
  • Gutur
    Avatar
    Community Member
    17 Posts

    ID of an entry in the DB before write()? Link to this post

    Aaand, me again

    This time I want to store a reference to the entry that I'm going to write.
    For testing I whipped up some code that tries to store the ID of the entry simply in an extra field, something like this:

    function saveCalEntry($data, $form) {
    $entry = new simpleCalEntry();
    $form->saveInto($entry);
    $IDofthisdata = $entry->ID; // How do I get the ID of this new entry?
    $entry->recurring = $IDofthisdata;
    $entry->write();
    }

    But unfortunately it seems that ID isn't set before write(). Any ideas on how I could go for it?

    Thanks in advance /Carsten

  • Gutur
    Avatar
    Community Member
    17 Posts

    Re: ID of an entry in the DB before write()? Link to this post

    Answering myself again, got the hint from ajshort:
    No, you can't easily get the ID of an entry before write() but you can get it immediately afterwards then fiddle what you want and call write() again.
    Easy, huh? ;)
    /Carsten

    1551 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.