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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

write() updates _Live table only


Go to End


4 Posts   3767 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