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,