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 /

Missing ParentID Field During Get


2 Posts   1158 Views


Community Member, 3 Posts

24 May 2011 at 7:54am

Edited: 24/05/2011 7:55am

Hi Everyone,

Long time stalker, first time poster. I'm still a SilverStripe noob so please be gentle. I'm working with a Course class and a page that has_many Courses. Defined below:

   class Course extends DataObject {
      static $db = array(
         "Name" => "Varchar",
         "Number" => "Int",
         "Description" => "Text",
         "Active" => "Boolean"
      static $has_one = array(
         "Category" => "CourseCategory"
      public function getCMSFields_forPopup()
         $categories = DataObject::get("CourseCategory");
         $dropdown = new DropdownField('Category');
         if ($categories) {
            $map = $categories->toDropDownMap('ID', 'Name');   
            $dropdown = new DropdownField('CategoryID', 'Category', $map);
         return new FieldSet(
            new TextField('Name'),
            new TextField('Number'),
            new TextareaField('Description'),
            new CheckboxField('Active')

class CoursesPage extends StandardPage {

   static $has_many = array(
      "Courses" => "Course"

   public function getCMSFields() {
      $fields = parent::getCMSFields();
      $course_fields = new DataObjectManager(
         array("Category.Name" => "Category", "Number" => "Number","Name" => "Name", "Description" => "Description", "Active" => "Active"),
      $course_category_fields = new DataObjectManager(
         array("Name" => "Name"),

      $fields->addFieldToTab("Root.Content.Courses", $course_fields);
      $fields->addFieldToTab("Root.Content.Categories", $course_category_fields);
      return $fields;


class CoursesPage_Controller extends StandardPage_Controller {

   public function init() {

The front-end errors out with the following when I try to call Courses:

Error at sapphire/core/model/MySQLDatabase.php line 525: Couldn't run query:
SELECT "Course"."ClassName", "Course"."Created", "Course"."LastEdited", "Course"."Name", "Course"."Number", "Course"."Description", "Course"."Active", "Course"."CategoryID", "Course"."ID", CASE WHEN "Course"."ClassName" IS NOT NULL THEN "Course"."ClassName" ELSE 'Course' END AS "RecordClassName"
FROM "Course"
WHERE ("ParentID" = '11')

Unknown column 'ParentID' in 'where clause' ({SITE_URL}/courses)

At one point I actually dropped Course and CourseCategory from the Database because they were giving me so many problems. Now I feel like that missing field is a product of myself messing with the database. I'm hoping there's an easy solution to this or I've overlooked something.

Many thanks!


Community Member, 3 Posts

25 May 2011 at 3:42am

Figured it out. I missed the fact that a $has_many relationship requires a $has_one on the related class.