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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Override the "Created" property


Go to End


2 Posts   1217 Views

Avatar
rob.s

Community Member, 78 Posts

13 August 2011 at 7:15pm

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

Avatar
martimiz

Forum Moderator, 1391 Posts

14 August 2011 at 4:40am

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