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, biapar, Willr, Ingo, swaiba, simon_w

many_many relation in same table?


2 Posts   1023 Views

Krille Brocket

27 December 2009 at 6:30pm (Last edited: 27 December 2009 6:32pm), Community Member, 10 Posts

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


27 December 2009 at 10:52pm (Last edited: 27 December 2009 10:57pm), Community Member, 279 Posts

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.