Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Issue with DataExtension and $many_many

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 292 Views
  • C-D
    Community Member
    1 Post

    Issue with DataExtension and $many_many Link to this post

    Hi guys,

    I've got an issue that I'm hoping someone can help with.

    I've set up a DataExtension called BlogEntryExtension, which is applied to BlogEntry. I've also got a custom DataObject of class BlogCategory. So far so good.

    BlogEntryExtension adds
    $many_many = array('BlogCategories' => 'BlogCategory');

    BlogCategory contains
    $belongs_many_many = array('BlogEntries' => 'BlogEntry');

    The idea being that a BlogEntry can belong to many categories, and a category can contain multiple BlogEntries.

    My issue is twofold. Firstly, I assumed that $this->owner->BlogCategories() from within BlogEntryExtension would return me the related BlogCategories. It doesn't - it returns ALL BlogCategories in the database.

    Secondly, when I create a GridField Relation Editor for this relationship, it doesn't reflect the relationship, instead showing ALL BlogCategories again.

    Has anyone encountered this before? Is many_many within DataExtensions not supported, or have I just misused something?

    Thanks in advance.

  • Willr
    Forum Moderator
    5508 Posts

    Re: Issue with DataExtension and $many_many Link to this post

    many_many should be supported in extensions fine and $this->owner->BlogCategories() should get you just the relations. There isn't a method called BlogCategories on your BlogEntry or any extensions that is overriding the SilverStripe __get() is there?

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.