7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » ParentID not needed... Maybe?
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 2100 Views |
-
ParentID not needed... Maybe?

18 December 2009 at 9:30am Last edited: 18 December 2009 9:30am
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");
}...
}
-
Re: ParentID not needed... Maybe?

18 December 2009 at 9:54am
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.
-
Re: ParentID not needed... Maybe?

18 December 2009 at 9:56am
explain.. please. I haven't see this in the wiki yet. That I know of.
-
Re: ParentID not needed... Maybe?

18 December 2009 at 9:56am
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")
);
}}
???
-
Re: ParentID not needed... Maybe?

18 December 2009 at 10:14am
If HomePage has_many RotatorImg, then RotatorImg needs a has_one HomePage.
-
Re: ParentID not needed... Maybe?

18 December 2009 at 10:17am
ooooooooooooooooooooooooooooooooooooooo TY....
-
Re: ParentID not needed... Maybe?

18 December 2009 at 10:24am
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")
);
}
} -
Re: ParentID not needed... Maybe?

18 December 2009 at 10:25am
In the admin listing of rotator images. Right now the image is about full size...
| 2100 Views | ||
| Go to Top | Next > |

