Jump to:

3432 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » NULL values in Live table

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

Page: 1
Go to End
Author Topic: 362 Views
  • Bezzen
    Avatar
    Community Member
    6 Posts

    NULL values in Live table Link to this post

    I'm having a slightly weird problem. I'm trying to create a dataobject that will appear as a page in the site tree.

    The basic code is like this:

    $product = new Product();
    $product->Title = "Example";
    $product->ProductNumber = 666;
    $product->writeToStage('Stage');
    $product->publish('Stage', 'Live');

    If I do that and then go and watch the site tree everything looks all peachy. The new product has been added as a new published page.

    But if I have a look in the database tables I realize that while the Product draft table looks like its intended to all fields except the ID field in the Product_Live table is set to NULL.

    So if I do a:

    DataObject::get_one("Product", "ProductNumber = '666'");

    It will return nothing as ProductNumber is NULL in the _Live table.

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: NULL values in Live table Link to this post

    What does the "Product" class look like?

  • Bezzen
    Avatar
    Community Member
    6 Posts

    Re: NULL values in Live table Link to this post

    It goes a little something like this:

    class Product extends Page {

    public static $db = array(
    "ProductNumber" => "Text",
    "Preamble" => "HTMLText",
    "ProductDescription" => "HTMLText",
    "OldItemID" => "Int",
    "OldProduct_Description_X" => "HTMLText",
    "OldImage_Product_Number" => "HTMLText",
    "OldMID" => "Int",
    "ForSale" => "boolean",
    );

    public static $has_one = array(
    "MainPic" => "Image"
    );

    static $has_many = array(
    "ProductPics" => "ProductPic"
    );

    static $many_many = array(
    'Markets' => 'Market',
    "Accessories" => "Product",
    "SpareParts" => "Product",
    "SimilarProducts" => "Product",
    "ProductContactPersons" => "ProductContactPerson",
    );

    static $multilingual_fields = array(
    "TechSpec", "Preamble", "ProductDescription", "OldProduct_Description_X",
    );

    I've run out of both good and bad ideas now.

    With a $product->write(); I can get it to the _Live table, but then it's not in the draft. I can't seem to have them both at the same time. Unless I go into the CMS and hit the Save & Publish button, because that takes care of it and moves it to _Live.

  • Bezzen
    Avatar
    Community Member
    6 Posts

    Re: NULL values in Live table Link to this post

    Forgot to mention that the data looks like its supposed to in Product_versions as well. It's just that damn _Live. Argh.

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