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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ParentID not needed... Maybe?


Go to End
Reply

11 Posts   2581 Views

Avatar
X10D3

18 December 2009 at 9:30am (Last edited: 18 December 2009 9:30am), Community Member, 10 Posts

From what I have read so far I would just need to do this to get my listing in the admin. Great so far It works I can add new items all is peachy. Until I go to edit. It gives me a SQL error and notifies me that it can't find the parentID field. What am I missing here?

SQL ERROR
[User Error] Couldn't run query: SELECT `RotatorImg`.*, `RotatorImg`.ID, if(`RotatorImg`.ClassName,`RotatorImg`.ClassName,'RotatorImg') AS RecordClassName FROM `RotatorImg` WHERE (ParentID = '1') ORDER BY SortOrder ASC Unknown column 'ParentID' in 'where clause'

Here's what I have

RotatorImg.php

class RotatorImg extends DataObject
{
   static $db = array(
      'RotLink' => 'Text',
      'RotImage' => 'Text'
   );
   
   function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('RotLink', "Rotator Link"),
         new TextField('RotImage', "Rotator Image")
      );
   }

}

HomePage.php

class HomePage extends Page
{
   public static $db = array();
   public static $has_one = array();   
   
   public static $has_many = array(
      'Rotator' => 'RotatorImg'
   );   
      
   function getCMSFields()
   {
      $fields = parent::getCMSFields();
      
      $fields->addFieldToTab("Root.Content.Rotator", new DataObjectManager(
         $this,
         'Rotator',
         'RotatorImg',
         array('RotLink' => 'Rotator Link','RotImage' => 'Rotator Image'),
         'getCMSFields_forPopup'
      ));
      return $fields;
   }
}

class HomePage_Controller extends ContentController
{

...

   function GetRotator()
   {
      return DataObject::get('RotatorImg', "RotImage IS NOT NULL", "SortOrder", "", "", "DataObjectSet");
   }

...

}

Avatar
UncleCheese

18 December 2009 at 9:54am 4085 Posts

You haven't reciprocated your has_many with a has_one on your DataObject, so it has to assume a foreign key of ParentID, and it's erroring out.

Avatar
X10D3

18 December 2009 at 9:56am Community Member, 10 Posts

explain.. please. I haven't see this in the wiki yet. That I know of.

Avatar
X10D3

18 December 2009 at 9:56am Community Member, 10 Posts

class RotatorImg extends DataObject
{
   static $db = array(
      'RotLink' => 'Text',
      'RotImage' => 'Text'
   );
   
   static $has_one = array();

   function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('RotLink', "Rotator Link"),
         new TextField('RotImage', "Rotator Image")
      );
   }

}

???

Avatar
UncleCheese

18 December 2009 at 10:14am 4085 Posts

If HomePage has_many RotatorImg, then RotatorImg needs a has_one HomePage.

Avatar
X10D3

18 December 2009 at 10:17am Community Member, 10 Posts

ooooooooooooooooooooooooooooooooooooooo TY....

Avatar
X10D3

18 December 2009 at 10:24am Community Member, 10 Posts

ok say that I do this (below). How would I get the image in the listing resized..

class RotatorImg extends DataObject
{
   static $db = array(
      'RotLink' => 'Text'
   );
   
   static $has_one = array(
      'HomePage' => 'HomePage',
      'RotImage' => 'Image'
   );
   
   function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('RotLink', "Rotator Link"),
         new ImageField('RotImage', "Rotator Image")
      );
   }
}

Avatar
X10D3

18 December 2009 at 10:25am Community Member, 10 Posts

In the admin listing of rotator images. Right now the image is about full size...

Go to Top