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   1285 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?