23477 Posts in 18941 Topics by 2878 members
|Go to End|
23 November 2010 at 4:46pm Last edited: 23 November 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?
24 November 2010 at 5:28pm
Anyone have any suggestions? People must have faced this issue before surely?
25 November 2010 at 9:07am Last edited: 25 November 2010 9:07am
maybe it is like the documentation says... http://doc.silverstripe.org/recipes:many_many-example
// 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.
|Go to Top|