Jump to:

3433 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » _live table not updating from table in CMS

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

Page: 1
Go to End
Author Topic: 2142 Views
  • Moose
    Avatar
    Community Member
    26 Posts

    _live table not updating from table in CMS Link to this post

    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?

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: _live table not updating from table in CMS Link to this post

    Did you fix this ?

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

  • zim
    Avatar
    Community Member
    135 Posts

    Re: _live table not updating from table in CMS Link to this post

    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?

  • Moose
    Avatar
    Community Member
    26 Posts

    Re: _live table not updating from table in CMS Link to this post

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

  • zim
    Avatar
    Community Member
    135 Posts

    Re: _live table not updating from table in CMS Link to this post

    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

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: _live table not updating from table in CMS Link to this post

    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 ?

  • Moose
    Avatar
    Community Member
    26 Posts

    Re: _live table not updating from table in CMS Link to this post

    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();
    }

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: _live table not updating from table in CMS Link to this post

    Hey... thanks for figuring that out !

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

    2142 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.