Jump to:

3432 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Through Relationship

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1184 Views
  • mh456
    Avatar
    Community Member
    5 Posts

    Through Relationship Link to this post

    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

  • jahbini
    Avatar
    Community Member
    13 Posts

    Re: Through Relationship Link to this post

    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

  • mh456
    Avatar
    Community Member
    5 Posts

    Re: Through Relationship Link to this post

    Thanks.

    And if nationalities are DataObjects themselves?

    1184 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.