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

write() updates _Live table only


Go to End


4 Posts   2400 Views

Avatar
jaybee

Community Member, 49 Posts

2 September 2010 at 3:45pm

I have a custom page type with a form, on the forms action I'm updating an object:

$myObj = DataObject::get_by_id("myObj", $Id);
$myObj->myProperty = 2;
$myObj->write();

But this only updates the _Live table and not the draft table, how can I update the draft table so it shows in the CMS?

Thank you

Avatar
jaybee

Community Member, 49 Posts

2 September 2010 at 4:35pm

Edited: 02/09/2010 4:35pm

All I needed was to add $myObj->publish("Live", "Stage"); after the write() function.

Thanks to this post which I found via google and not this forum search: http://www.silverstripe.org/archive/show/5780?showPost=6157&start=8

This forum really needs a better search feature, there is lots of information but you can't get to it :(

Avatar
Willr

Forum Moderator, 5523 Posts

2 September 2010 at 7:22pm

In the development version of the forum we now have the search powered by the much more useful sphinx search engine. Initial tests show results are better but we're still lacking an 'advanced' search form. This forum will be upgraded to include this sphinx search extension before the end of the year.

Avatar
Worik

Community Member, 5 Posts

30 August 2017 at 10:13am

I am having a very similar problem, but years later.

$contact = Contact::create();
$form->saveInto($contact);
$ret = $contact->write();
error_log("Wrote contact: $ret");

In the error log I get the ID, but it is for the contact_live table.
I can find no method 'publish'
In the examples , the 'one ring rentals' case that I copied from there is no '_live' table.
i am perplexed