Jump to:

23355 Posts in 17873 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » many_many relation in same table?

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

Page: 1
Go to End
Author Topic: 992 Views
  • Krille Brocket
    Avatar
    Community Member
    10 Posts

    many_many relation in same table? Link to this post

    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

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: many_many relation in same table? Link to this post

    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.

    992 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.