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


Go to End


2 Posts   1303 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.