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.

Data Model Questions /

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

DataObject Relationships - two has_many that relate to each other


Go to End


2 Posts   590 Views

Avatar
tuxibear

Community Member, 9 Posts

29 April 2017 at 12:04pm

After several hours and some Google Searching, i have run out of steam on this issue and could use some help.

So, the parent object is called Offer.
Each offer has two has_many objects : ItineraryItem and ItineraryTab
Now, the main issue i have is the relationship between these two objects.
I am trying to get it so that each Itinerary Item can have more than one Itinerary Tab, as I am trying to render the items in a tabbed list.

I have tried the following (which is constantly giving me errors when i try to get the offer content, so i am sure there is something wrong)

//Offer.php
$has_many = array(
   "ItineraryItems" => "ItineraryItem",
   "ItineraryTabs" => "ItineraryTab"
);

// On ItineraryItem
$has_one = array(
   "Offer" => "Offer"
);
$many_many = array(
   "ItineraryItems" => "ItineraryItem"
);

// on ItineraryItem
$has_one = array(
   "Offer" => "Offer"
);
$belongs_many_many = array(
   "ItineraryTabs" => "ItineraryTab"
);

Now, i am sure that there is a simple solution here, and i have simply been looking at it too long to see it. Please help!

Thanks in advance

Avatar
tuxibear

Community Member, 9 Posts

3 May 2017 at 6:21am