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.

Data Model Questions /

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

Issue with DataExtension and $many_many


Go to End


2 Posts   1467 Views

Avatar
C-D

Community Member, 1 Post

12 January 2014 at 5:46pm

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

Forum Moderator, 5523 Posts

18 January 2014 at 11:27am

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?