Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Override the "Created" property

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

Page: 1
Go to End
Author Topic: 849 Views
  • rob.s
    Avatar
    Community Member
    78 Posts

    Override the "Created" property Link to this post

    Hi,

    because of migrating data to a new SS Website i have to import data.
    The import itself is handled by a custom "Task".

    I need to set the "Created" (datetime) property while importing.
    But SS ignores the set values.

    E.g.:

    ...
    $o = new CustomDataObject();
    $o->Created = '2000-01-01 00:00:00';
    $o->write();

    After saving the Created datetime is always the datetime of execution - NOT my given value.
    I do not want to add a new property like "CreatedAt" to the DataObject.

    Is it possible to override this behaviour ?

    Greetings,
    Rob

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Override the "Created" property Link to this post

    the write() function will set Created to 'now' on every new insert. You could maybe use the return ID to update the record after it's written...

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