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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Show Relating DataObject as link? (Plus speed up record view in model admin)


Go to End


5 Posts   2277 Views

Avatar
swaiba

Forum Moderator, 1899 Posts

6 July 2010 at 11:25pm

Edited: 07/10/2010 2:16am

Hi,

I have several relations ($has_one) that are slowing down the speed of browsing the record inside model admin - because the relating table has a lot of rows and it is read ALL rows to create the drop down.

class ExampleObject extends DataObject
{
	static $db = array(
		'Stuff' => 'Text',
	);

	static $has_one = array(
		'RelationToBigTable' => 'BigTable',
	);
}

So I changed them to be read only text fields (as they are not for changing in the gui anyway!).

class ExampleObject extends DataObject
{
	static $db = array(
		'Stuff' => 'Text',
	);

	static $has_one = array(
		'RelationToBigTable' => 'BigTable',
	);

	function getCMSFields()
	{
		$fields = parent::getCMSFields();

		$fields->insertAfter(new ReadonlyField('readonlyfield','RelationToBigTableID',$this->RelationToBigTableID),'Stuff');
		$fields->removeByName('RelationToBigTableID');

		return $fields;
	}
}

I wonder if there is a way to link them to the other dataobject (also in the same model admin) so that I could turn it into a link and it would jump to editing that record?

Barry

Avatar
swaiba

Forum Moderator, 1899 Posts

7 October 2010 at 2:12am

Edited: 07/10/2010 2:21am

Hi,

On the off chance that this is of use to someone... here is the answer to my own question...

function getCMSFields()
{
	...
	$fields->insertBefore(
		new LiteralField('testlit', "<button onClick=\"jQuery('#ModelAdminPanel').fn('loadForm',
			'admin/<adminsection*>/<DataObject*>/<id*>/edit',function() {})\"> <buttonlabel*></button>"),'ExtraID');
	...
}

* fields need completing

Barry

Avatar
teejay

Community Member, 63 Posts

18 May 2011 at 5:28pm

I need this but i where do I need to put it ?? In the Dataobject ?

Avatar
purplespider

Community Member, 89 Posts

19 May 2011 at 12:30am

I'm interested in how to do this too, do let me know if you work it out.

Cheers

Avatar
swaiba

Forum Moderator, 1899 Posts

19 May 2011 at 1:52am

Edited: 19/05/2011 1:54am

where do I need to put it ?? In the Dataobject ?

yes

also I should point out I now use this rarely as I use this instead now...

$hasOneCTF = new HasOneComplexTableField($this,DATAOBJECTNAME,DATAOBJECTNAME,null,null,'ID='.$this->DATAOBJECTNAMEID);
$hasOneCTF->setPermissions(array('edit','show'));
$hasOneCTF->Markable = false;
$fields->addFieldToTab("Root.DATAOBJECTNAME", $hasOneCTF);

and the above link is actually the js called when tapping the edit button on the tab created by teh above code..