2580 Posts in 695 Topics by 540 members
Data Model Questions
SilverStripe Forums » Data Model Questions » Through Relationship
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 890 Views |
-
Through Relationship

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 -
Re: Through Relationship

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
-
Re: Through Relationship

1 June 2009 at 11:56am
Thanks.
And if nationalities are DataObjects themselves?
| 890 Views | ||
|
Page:
1
|
Go to Top |


