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.

Data Model Questions /

How to Relate Dataobject with page?


Reply


3 Posts   337 Views

Avatar
anudeepgi

Community Member, 11 Posts

29 January 2014 at 5:44pm

Hi,
I am new to silverstripe ,I need to create Dataobject(Ex:-CarAcs extends ModelAdmin) that is related to pages what ever you created in Dataobject it will showen as dropdown menu in page so we can realate data and show it in page , Please given me a simple example of doing it with all code thanks in advance ..

Avatar
Willr

Forum Moderator, 5513 Posts

29 January 2014 at 8:02pm

Have a read of tutorial 5 (http://doc.silverstripe.org/framework/en/tutorials/5-dataobject-relationship-management). This will explain relationships and the concept of relating objects in SilverStripe.

On your Page class you might have something like

private static $has_one = array(
"Car" => "CarAcs"
);

Then in your getCMSFields for Page add the DropdownField.

public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new DropdownField('CarID', 'Car', CarAcs::get()->map('ID', 'Title')));

return $fields;
}

Where 'CarAcs' is the name of your class. This relationship will add $page->Car() to get the car.

Avatar
anudeepgi

Community Member, 11 Posts

29 January 2014 at 8:12pm

Again Thanx bro, your always there for help.

Can you help one more time..

I need to get all infomation from Related to Cars object and pass it to view .... Please