Jump to:

3372 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Control all descendants of a given class name

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

Page: 1
Go to End
Author Topic: 1040 Views
  • stallain
    Avatar
    Community Member
    61 Posts

    Control all descendants of a given class name Link to this post

    Hello,

    My site structure :

    ArticleHolder
    ------------ArticleHolder
    ------------------------Article
    ------------------------Article
    ------------------------Article
    ------------ArticleHolder
    ------------------------Article
    ------------------------Article
    ArticleHolder
    ------------ArticleHolder
    ------------------------Article
    ------------------------Article
    ------------ArticleHolder
    ------------------------Article
    ------------------------Article
    ...

    I want to control all the Articles being descendant of any ArticleHolder page. No problem with direct children ; but what if the articles are grandchildren of my ArticleHolder page ?

    What I did to solve this is :

    1°/ replace the class name of my top level pages (new name : "TopArticleHolder")

    TopArticleHolder
    ------------ArticleHolder
    ------------------------Article
    TopArticleHolder
    ------------ArticleHolder
    ------------------------Article

    2°/ set a one-to-many relationship between my Articles and my TopArticleHolder Pages : every TopArticleHolder has many Articles, and every Article has one TopArticleHolder

    3°/ include a HasOneComplexTableField in my Article.php file, so that I can tick the TopArticleHolder page of my article in the cms.

    4°/ I can now control my Articles, sort them, etc. from my TopArticleHolder page template with <% control Articles %>

    But I don't find this solution elegant at all !

    Do you know any cleaner way to control grandchildren ?
    If I have to stick to my solution, how can I define my has_one relationship by default, without my tablefield, given that an Article is always related to its top ascendant ?

    Thank you !

    Stan

    1040 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.