Reputation: 111
I have two dataobjects related with many_many and an extrafield. My plan is to group the result by the extrafield. Maybe someone has an idea.
class Saison extends DataObject {
private static $db = [
"Name"=> "Varchar(200)",
"Jahr" => "Int(4)"
];
private static $many_many = [
"Team" => Teams::class
];
private static $many_many_extraFields = [
'Team' => [
'Gruppe' => 'Varchar'
]
]; }
class Teams extends DataObject {
private static $db = [
"Name" => "Varchar(300)",
"TeamName" => "Varchar(300)"
];
private static $has_one = [
];
private static $has_many = [
];
private static $belongs_many_many = [
"Saison"=>Saison::class
]; }
function Teams() {
return GroupedList::create(Saison::get()->filter(array("ID" => $this->Saison()->ID)));
<% loop $Teams %>
<% loop $Team.GroupedBy(Gruppe) %>
$Gruppe<br />
<% end_loop %>
<% end_loop %>
With this way I don't get the data.
Upvotes: 1
Views: 166
Reputation: 111
I found a solution. Because of the many_many and the belongs_many_many there is a table called Saison_Team. I just created a class Saison_Team which uses this table. So I can use this dataobject and the relations.
Upvotes: 1