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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Extending more than one "level"?


Go to End


4 Posts   1369 Views

Avatar
dynamite

Community Member, 66 Posts

29 August 2009 at 8:42am

Hello,

I am having problems getting the DataObjectManager to properly associate items when it is being used in more than one level of class inheritance. (sorry if I am using the wrong language to describe this!)

Here is what I have now:

In the "Page" class itself I am adding a "has_many" relationship to "BannerImages"

"ArticlePage" extends "Page" and has two additional "has_many" relationships, one to "ArticleImages" and another to "ArticleFiles"

ArticleImages and ArticleFiles work beautifully.

But BannerImages keeps getting associated with seemingly all, or random, Pages and ArticlePages! What gives?

I took a peak at the database table BannerImage and see that the PageID is the foreign key. Do my ArticlePages use a PageID, too, or does ArticlePageID override that?

Thanks for any insight!

Jeremy

Avatar
UncleCheese

Forum Moderator, 4102 Posts

29 August 2009 at 9:29am

Hi, Jeremy,

Make sure you have your model set up as follows:

Page -> has_many "BannerImages"
BannerImage -> has_one "Page"

ArticlePage -> has_many "ArticleImages"
ArticlePage -> has_many "ArticleFiles"

ArticleFile -> has_one "ArticlePage"
ArticleImage -> has_one "ArticlePage"

If you're using a DOM on Page class, you need to be sure to use setParentClass("Page") because you're passing $this as the controller and if $this is an ArticlePage, it will try to set ArticlePageID on your BannerImage, which of course is a non-existent field.

Avatar
dynamite

Community Member, 66 Posts

29 August 2009 at 11:45am

Thanks UncleCheese...

I did triple-check the model has_many and has_one, and I know that is working.

Does the "setParentClass" go in the getCmsFields of ArticlePage then?

I am familiar with DOM for HTML and JavaScript, but not with PHP.

Thanks again!

Avatar
dynamite

Community Member, 66 Posts

29 August 2009 at 11:45am

D'oh, I just realized DOM is short for DataObjectManager... sorry! I will try your suggestion.