Jump to:

3462 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Problems extending Page

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

Page: 1
Go to End
Author Topic: 1179 Views
  • david_nash
    Community Member
    55 Posts

    Problems extending Page Link to this post


    I'm trying to extend Page. What I want is for each page to have a tab called 'Products' in the CMS, which would show a table of products. Each product would be one image and a title.

    I think what I've done is correct but when I go to the admin I get:

    [User Error] Couldn't run query: SELECT `Product`.*, `Product`.ID, if(`Product`.ClassName,`Product`.ClassName,'Product') AS RecordClassName, `0`, `1` FROM `Product` LIMIT 0,10 Unknown column '0' in 'field list'

    What I did was edit mysite/code/Page.php and added to class Page:

    $has_many = array( 'MyProducts' => 'Products');

    Then I created mysite/code/Product.php :

       class Product extends DataObject {
          public static $db = array(
             'ProductTitle' => 'Text'

          public static $has_one = array(
             'MyPage' => 'Page',
             'ProductImage' => 'Image'

       } //end class

    I ran /db/build/?flush=1 and it did the update with no complaints.

    I think this is right, with this model the each row of the database table would have a text field 'ProductTitle' and then an id of the page it's associated with and the id of an image.

    When I go to the CMS I get the MySQL error above. Where is the `0` and `1` coming from?

    I thought this might be due to there already being a 'Product' in Silverstripe so I changed 'Product' to 'GalleryItem' and I still get the same error.

    Thanks for your help.


  • david_nash
    Community Member
    55 Posts

    Re: Problems extending Page Link to this post

    Okay I think I've solved it!

    I've found that the model is fine, the problem was occuring in getCMSFields() in Page.php

    When I was creating a new HasManyComplexTableField() object I wasn't giving it an array for the $fieldList.

    I should have had


    where I actually had


    I hope this helps someone else who's getting the confusing mysql error from the admin!

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.