Jump to:

23487 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » SS3 Join Sort help

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 276 Views
  • mr3xcellent
    Avatar
    Community Member
    2 Posts

    SS3 Join Sort help Link to this post

    I'm trying to get a list of pages sorted by their Parent's Title.

    I have two page types I'm working with here:

    class AgencyPage extends Page {

       public static $db = array(
          'City' => 'Varchar',
          'State' => 'Varchar',
          'AgencyURL' => 'Varchar'
       );

       public static $has_one = array(
    'Logo' => 'Image',
          'AccountExec' => 'Member'
       );
       
       public static $has_many = array(
          'Contacts' => 'Member.Agency'
       );

    AND

    class ProjectPage extends Page
    {
       public static $db = array(
          'Description' => 'Text',
          'JobNumber' => 'Int',
          'ProjectCode' => 'Varchar(6)',
          'isArchived' => 'Boolean',
          'ArchivedDate' => 'SS_Datetime'
       );

       public static $has_one = array(
          'ArchivedBy' => 'Member',
          'CreatedBy' => 'Member'
       );
       
       public static $has_many = array(
          'ProjectFiles' => 'ProjectFile'
       );
       
       public static $many_many = array(
          'ProjectContacts' => 'Member',
          'ProjectViewers' => 'Member'
       );

    AgencyPage will be above ProjectPage in SiteTree (ProjectPage.ParentID = Agency.ID)

    So, on the "All Projects" page, I list all the (current) projects. It's easy to sort my ProjectPage's by Title, Created, JobNumber, etc., but I'd like to allow the user to sort by the agency, or other 'joined' date, but can't seem to figure out how to get my DataList sorted that way.

    What I'd like to be able to do is:

    ProjectPage::get()->leftJoin('AgencyPage', 'ProjectPage.ParentID = AgencyPage.ID')->sort('AgencyPage.Title');

    But this doesn't work as I get "Unknown column 'AgencyPage.Title' in 'field list'". This is because the joined table's columns aren't brought over, right?

    I know I've seen similar questions before, but can't seem to relate their solutions to my situation.

    What I'd like to know is what is the appropriate way to sort joined data within SS3? Any insight you kind folks can provide will be appreciated.

    Thanks in advance,

    276 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.