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.

Data Model Questions

_live table not updating from table in CMS


Reply

8 Posts   2169 Views

Avatar
Moose

8 May 2009 at 11:12pm Community Member, 26 Posts

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

22 October 2009 at 10:52pm Community Member, 787 Posts

Did you fix this ?

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

Avatar
zim

14 November 2009 at 10:04am Community Member, 135 Posts

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

15 November 2009 at 11:15pm (Last edited: 15 November 2009 11:16pm), Community Member, 26 Posts

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

16 November 2009 at 11:31am Community Member, 135 Posts

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

16 November 2009 at 9:46pm Community Member, 787 Posts

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

2 April 2010 at 12:19am Community Member, 26 Posts

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

2 April 2010 at 12:32am Community Member, 787 Posts

Hey... thanks for figuring that out !

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