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

ParentID not needed... Maybe?


Go to End
Reply


11 Posts   2953 Views

Avatar
X10D3

Community Member, 10 Posts

18 December 2009 at 9:30am

Edited: 18/12/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");
	}

...

}

Avatar
UncleCheese

Forum Moderator, 4096 Posts

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.

Avatar
X10D3

Community Member, 10 Posts

18 December 2009 at 9:56am

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

Avatar
X10D3

Community Member, 10 Posts

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

}

???

Avatar
UncleCheese

Forum Moderator, 4096 Posts

18 December 2009 at 10:14am

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

Avatar
X10D3

Community Member, 10 Posts

18 December 2009 at 10:17am

ooooooooooooooooooooooooooooooooooooooo TY....

Avatar
X10D3

Community Member, 10 Posts

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

Avatar
X10D3

Community Member, 10 Posts

18 December 2009 at 10:25am

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

Go to Top