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.

Data Model Questions /

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

HasManyComplexTable data extraction/manipulation


Go to End


1795 Views

Avatar
DigoART

Community Member, 13 Posts

6 July 2009 at 9:59pm

Hi All,

I ran into interesting problem, which I can't solve in a easy way, so thought someone could help me on that. (Well, I think the solution could be in interest for other members)

The situation is -
1. I've got a list of services which are extended from "Page" class and are used as a pages of services description on the website.
These have Many_many relation to Case studies:

 	  
      static $belongs_many_many = array(
      'CaseStudy' => 'CaseStudy'
      );

2. I've got a Case studies list , which would include several Services out of all of services

   static $many_many = array(
      'Services' => 'Services'
   );
.
.
.

                 $tablefield = new ManyManyComplexTableField(
    				        $this,
					'Services',
					'Services',
					array(
					'Title' => 'Title'
					 ),
					'getCMSFields_forPopup'
				);
		$tablefield->setPermissions(array('print'));
		
		$f->addFieldToTab("Root.Content.Services", $tablefield); 

Admin adds services as pages, and then can tick the checkbox for each CaseStudy , to indicate which services where used for the particular case study.

Now the problem to be solved:

On the case study page I need outputting ALL of the services , however those that are checked for that case study should have different highlighting color. I thought of approach where I' would select all services in one query, selected service in other query , run a one-by-one comparison, adding extra value, for those that should be highlighted. However , it looks to me that this could be somehow in a more "proper" datamodel approach, so if you have any ideas how to implement that in a proper way - would appreciate your help.