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

NULL values in Live table


Go to End


4 Posts   1160 Views

Avatar
Bezzen

Community Member, 6 Posts

9 January 2013 at 7:39am

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.

:(

Avatar
swaiba

Forum Moderator, 1899 Posts

9 January 2013 at 8:11am

What does the "Product" class look like?

Avatar
Bezzen

Community Member, 6 Posts

9 January 2013 at 10:23am

Edited: 09/01/2013 11:56am

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

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.

Avatar
Bezzen

Community Member, 6 Posts

9 January 2013 at 11:55am

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