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.

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 relation in same table?

Go to End

2 Posts   1201 Views

Krille Brocket

Community Member, 10 Posts

27 December 2009 at 6:30pm

Edited: 27/12/2009 6:32pm

Can any1 explain how i can create a working many_many relation using only one table, ie
One Article should be able to hold many other articles

class Article {
static $many_many = array("NewsArticles"=>"Article");

function getCMSFields() {
$fields = parent::getCMSFields();
$table = new ManyManyComplexTableField(

$fields->addFieldToTab("Root.Content.Related Articles",$table);
return $fields;

the available articles are displayed in the table, but if i check the checkbox and
saves the page, the relation isnt saved


Community Member, 279 Posts

27 December 2009 at 10:52pm

Edited: 27/12/2009 10:57pm

A many_many relation always needs a third table in SilverStripe. Your code has a big error anyways. Your class Article has a relation to itself. That´s not possible, nor logical.