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

_live table not updating from table in CMS


Go to End


8 Posts   3499 Views

Avatar
Moose

Community Member, 26 Posts

8 May 2009 at 11:12pm

I have a 1 - many relationship defined allowing me to associated multiple objects with my home page ('featured items' functionality). When I check or uncheck the objects in the CMS and then Save and Publish the associations are not correctly updated. Looking at the underlying tables I see that the core table has updated (in my case BookPage) but not the live table (in my case BookPage_Live).

Any idea what could be causing this?

Avatar
Fuzz10

Community Member, 791 Posts

22 October 2009 at 10:52pm

Did you fix this ?

I'm experiencing the exact same problem at the moment...

Avatar
zim

Community Member, 135 Posts

14 November 2009 at 10:04am

I have the same problem. Changes I make on saving page, which occur with raw sql statement in
function onBeforeWrite() {

// call parent first
parent::onBeforeWrite();

// check if MainStory is true
if( $this->IsMainStory ){
// if yes, make sure no other story is main-story
// we use a raw sql query here to set all IsMainStory to 0
DB::query('UPDATE ' . $this->ClassName . ' SET IsMainStory=0');

DB::query('UPDATE ' . $this . ' SET IsMainStory=1 WHERE ID=' . $this->ID);

}

Are not reflected in Live database but are in core? Anyone know why?

Avatar
Moose

Community Member, 26 Posts

15 November 2009 at 11:15pm

Edited: 15/11/2009 11:16pm

I unfortunately still haven't figured this out! I hoped the Silverstripe book may elucidate the usage of the version tables but as excellent as it is I haven't yet found the clues I needed to solve this problem. Maybe v 2.4 will sort it out. I'll post any progress that I make...

Avatar
zim

Community Member, 135 Posts

16 November 2009 at 11:31am

In my case the problem was that I was using raw sql update a table. I found out that

"
you should never update directly to the live tables since it will lead to syncing problems when you re-publish a page and erase your data...
"

so found out how to update table another way in following function.... not sure if this will help but thought I'd let you know.

see this thread

http://silverstripe.org/general-questions/show/273211?start=8#post273347

Avatar
Fuzz10

Community Member, 791 Posts

16 November 2009 at 9:46pm

Unfortunately , I'm not using raw SQL commands to update a table but alter everything through a default "has_many" relationshop (exactly the same problem as TS). Any ideas ?

Avatar
Moose

Community Member, 26 Posts

2 April 2010 at 12:19am

I have discovered at the reason for this problem is that when using a HasManyComplexTableField the changes are not published when the page containing the HasManyComplexTableField is published. What is required is to force the publication of the page objects on the 'many' side of the relationship in the onBeforeWrite event: something like this

public function onBeforeWrite() 
 {
  $hasManyPages = DataObject::get("MyHasManyPage");
  if($hasManyPages ) 
  {
   foreach($hasManyPage as $page) {
    $page->writeToStage('Stage');
    $page->publish('Stage', 'Live');
    $page->flushCache();
   }
  }
  parent::onBeforeWrite();
 }

Avatar
Fuzz10

Community Member, 791 Posts

2 April 2010 at 12:32am

Hey... thanks for figuring that out !

It seems so logical once you know.. But we could not not figure this one out ... ;-)