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.

Data Model Questions /

Control all descendants of a given class name


Reply


1145 Views

Avatar
stallain

Community Member, 61 Posts

26 April 2011 at 3:05am

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