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.

Data Model Questions

Through Relationship


Reply

3 Posts   1212 Views

Avatar
mh456

29 May 2009 at 10:44pm Community Member, 5 Posts

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

31 May 2009 at 3:17pm Community Member, 13 Posts

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

1 June 2009 at 11:56am Community Member, 5 Posts

Thanks.

And if nationalities are DataObjects themselves?