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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Sorting on has_one relation field


Go to End


2 Posts   1116 Views

Avatar
Chazz

Community Member, 7 Posts

15 May 2015 at 2:54am

Edited: 15/05/2015 2:57am

Hi there,
I tried the following with 3.1.12 to set the default sort of the dataobject Feature:

<?php
class FeatureGroup extends DataObject {

    private static $db = array(
        'Name' => 'VarChar',
        'Sort' => 'Int',
    );


class Feature extends DataObject {

    private static $db = array(
        'Name' => 'VarChar',
        'TopName' => 'VarChar',
        'Sort' => 'Int',
        'ShowInComparison' => 'Boolean',
        'ShowInList' => 'Boolean'
    );

    private static $has_one = array(
        'FeatureGroup' => 'FeatureGroup',
    );

private static $default_sort = "FeatureGroup.Sort, Sort";

and got this error:

[User Error] Couldn't run query: SELECT DISTINCT "InsurancePage_Features"."Text", "Feature"."ClassName", "Feature"."Created", "Feature"."LastEdited", "Feature"."Name", "Feature"."TopName", "Feature"."Sort", "Feature"."ShowInComparison", "Feature"."ShowInList", "Feature"."FeatureGroupID", "Feature"."ID", CASE WHEN "Feature"."ClassName" IS NOT NULL THEN "Feature"."ClassName" ELSE 'Feature' END AS "RecordClassName", "FeatureGroup"."Sort" AS "_SortColumn0" FROM "Feature" INNER JOIN "InsurancePage_Features" ON "InsurancePage_Features"."FeatureID" = "Feature"."ID" WHERE ("InsurancePage_Features"."InsurancePageID" = '16') ORDER BY "_SortColumn0" ASC, "Feature"."Sort" ASC Unknown column 'FeatureGroup.Sort' in 'field list'

The FeatureGroup table doesn't seem to be joined.
I found [https://github.com/silverstripe/silverstripe-framework/pull/3019]https://github.com/silverstripe/silverstripe-framework/pull/3019/, so this seems to have been fixed. Why do I still get the error?

Thanks in advance

Avatar
Pyromanik

Community Member, 419 Posts

19 May 2015 at 8:41pm

You've not shown how you get this error.
It looks like you're not asking for groups anywhere. An object is just an object, not an object AND all it's has_one relations. This trips some Laravel converts up.
If you think that because it's in the default sort it should be included, then you should log a github issue :)