3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 626 Views |
-
SS3 many-to-many relations

21 July 2012 at 4:22am Last edited: 31 July 2012 9:02am
Hello all,
I just try to set up a many-to-many relation between two Dataobjects. Let´s say Events and Countries.
An event can be assigned to many countries and one country could be assigned to many events.The relation setup seems to work basically. I have a Gridfield in the EventsPage showing all Events:
//EventItem.php
static $many_many = array(
'CountryItems' => 'CountryItem'
);//CountryItem.php
static $belongs_many_many = array(
'EventItems' => 'EventItem'
);//EventPage.php
function getCMSFields() {
$fields = parent::getCMSFields();
$gridfield = new GridField("Events", "My Events", $this->Events(), new GridFieldConfig_RelationEditor());
$fields->addFieldToTab('Root.Events', $gridfield);
return $fields;
}If I click an Event there appears a Tab in the right top corner showing the countries. I can add and delete countries there. But they are only assigned to a single event (the one that was previously selected). I need a country list showing all countries that were ever created and with a checkbox for each country. so I can add and remove countries with just setting or deleting the relation. I think in former days it was called ManyManyComplexTableField...
any help is highly appreciated.
many thanx,
florian -
Re: SS3 many-to-many relations

14 October 2012 at 1:35pm
on the event page you're setting up the grid field, but getting events with $this->Events()
however, there is nothing to connect to the event to the event page?I guess 2 options - link to the 'event' to the 'event page' with many_many or has_many relation, or make 'event' into 'eventpage' so each event is it's own page
I've written up some notes on this here http://www.silverstriperesources.com/articles/silverstripe-3-many-many-a-comprehensive-example/
I've actually put a "getCMSFields() { }" function on both sides to control it a bit better
| 626 Views | ||
|
Page:
1
|
Go to Top |


