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 /

Problems extending Page


Reply


2 Posts   1198 Views

Avatar
david_nash

Community Member, 55 Posts

6 March 2009 at 5:47pm

Hello

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

Avatar
david_nash

Community Member, 55 Posts

6 March 2009 at 6:33pm

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

array('Title'=>'ProductTitle')

where I actually had

array('ProductTitle')

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