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.

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   1673 Views

Avatar
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(
$this,
'NewsArticles',
'Article'
);

$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

Avatar
baba-papa

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.