7912 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Extending more than one "level"?
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 792 Views |
-
Extending more than one "level"?

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
-
Re: Extending more than one "level"?

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.
-
Re: Extending more than one "level"?

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!
-
Re: Extending more than one "level"?

29 August 2009 at 11:45am
D'oh, I just realized DOM is short for DataObjectManager... sorry! I will try your suggestion.
| 792 Views | ||
|
Page:
1
|
Go to Top |

