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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[solved] Loop in has_many


Go to End


718 Views

Avatar
m4kx

Community Member, 5 Posts

31 August 2015 at 8:47pm

Edited: 02/09/2015 9:49pm

Hello!

So i have these Databoject

class DishCategory extends DataObject {
	private static $has_many = [
		'Dishes' => 'Dish'
	];
}

class Dish extends DataObject {	
	private static $has_one = [
		'DishCategory' => 'DishCategory'
	];
}

I'd like to add them in pages this way
<% loop $DishCategory %>
	$Title
	<% loop $Dishes %>
		$Title
	<% end_loop %>
<% end_loop %>

to get the display
   Category 1
     Dish 1.1
     Dish 1.2
     Dish 1.3
   Category 2
     Dish 2.1
     Dish 2.2
     Dish 2.3
...

corr: sorry this actually works... the problem was a mistake i did in my code so... nvm ^^
Bye