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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Many Many Relationships

Go to End

3 Posts   1379 Views


Community Member, 21 Posts

23 November 2010 at 4:46pm

Edited: 23/11/2010 4:47pm

Im having a bit of a hard time working out the best way to structure what I think is a $many_many relationship. I have a Business class and an Event class. Businesses can be associated with multiple Events, and Events can be associated with multiple Businesses.

What Im not sure of is which is the correct class to put the $many_many, and which is the correct class to put the $belongs_many_many? It almost seems as if BOTH classes need a $many_many AND a $belongs_many_many? Is that the correct way to approach it?


Community Member, 21 Posts

24 November 2010 at 5:28pm

Anyone have any suggestions? People must have faced this issue before surely?


Forum Moderator, 1899 Posts

25 November 2010 at 9:07am

Edited: 25/11/2010 9:07am

maybe it is like the documentation says...

// Defines the join in the referenced class as $belongs_many_many.
// a new table, (this-class)_(relationship-name), will be created with a pair of ID fields.
static $belongs_many_many = array('Articles' => 'Article'

// an Article can have many Category objects associated with it.
// calling $this->getManyManyComponents('Categories') retrieves the associated Category objects.
static $many_many = array('Categories' => 'Category'

I can't remember whether I've ever had trouble doing ->RelationshipName() on either of the two sides... or if it has affected how is appears when scaffolded with modeladmin... but you can try it out and see... those are the things I'd test to see if there was a difference.