Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Extending more than one "level"?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 906 Views
  • dynamite
    Avatar
    Community Member
    66 Posts

    Extending more than one "level"? Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Extending more than one "level"? Link to this post

    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.

  • dynamite
    Avatar
    Community Member
    66 Posts

    Re: Extending more than one "level"? Link to this post

    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!

  • dynamite
    Avatar
    Community Member
    66 Posts

    Re: Extending more than one "level"? Link to this post

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

    906 Views
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.