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.

Data Model Questions

Issue with DataExtension and $many_many


Reply

2 Posts   305 Views

Avatar
C-D

12 January 2014 at 5:46pm Community Member, 1 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.

Avatar
Willr

18 January 2014 at 11:27am Forum Moderator, 5511 Posts

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?