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

Through Relationship


Go to End


3 Posts   2149 Views

Avatar
mh456

Community Member, 5 Posts

29 May 2009 at 10:44pm

Example:
A team has many players (or rather, each player has exactly one team).
Each player has exactly one nationality.

Is there a built-in function to easily query all nationalities of one team?

Something like
DataObject::get_one('Team', 'Tiny Giants')->Players()->Nationalities();
or
DataObject::get_one('Team', 'Tiny Giants')->Nationalities(); // this is, BTW, RoR syntax for has_many :through

Avatar
jahbini

Community Member, 13 Posts

31 May 2009 at 3:17pm

My suggestion would be function column of DataObjectSet, as in:

DataObject::get_one('Team', 'Tiny Giants')->Players()->column('Nationality'); // returns an array for method or data item 'Nationality'

It is (currently) defined on or about line 675 of file sapphire/core/model/DataObjectSet.php

Avatar
mh456

Community Member, 5 Posts

1 June 2009 at 11:56am

Thanks.

And if nationalities are DataObjects themselves?