Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ParentID not needed... Maybe?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 2509 Views
  • X10D3
    Avatar
    Community Member
    10 Posts

    ParentID not needed... Maybe? Link to this post

    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");
       }

    ...

    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: ParentID not needed... Maybe? Link to this post

    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.

  • X10D3
    Avatar
    Community Member
    10 Posts

    Re: ParentID not needed... Maybe? Link to this post

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

  • X10D3
    Avatar
    Community Member
    10 Posts

    Re: ParentID not needed... Maybe? Link to this post

    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")
          );
       }

    }

    ???

  • UncleCheese
    Avatar
    4085 Posts

    Re: ParentID not needed... Maybe? Link to this post

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

  • X10D3
    Avatar
    Community Member
    10 Posts

    Re: ParentID not needed... Maybe? Link to this post

    ooooooooooooooooooooooooooooooooooooooo TY....

  • X10D3
    Avatar
    Community Member
    10 Posts

    Re: ParentID not needed... Maybe? Link to this post

    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")
          );
       }
    }

  • X10D3
    Avatar
    Community Member
    10 Posts

    Re: ParentID not needed... Maybe? Link to this post

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

    2509 Views
Page: 1 2
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.