Jump to:

9526 Posts in 1941 Topics by 1529 members

All other Modules

SilverStripe Forums » All other Modules » DataObjectManager unable to sort joined Fields ?

Discuss all other Modules here.

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba

Page: 1
Go to End
Author Topic: 1897 Views
  • Rufinus
    Avatar
    Community Member
    6 Posts

    DataObjectManager unable to sort joined Fields ? Link to this post

    Hi,

    Imaging the following DataObjectManager Setting:

    /** Kurs Tab **/
    $pl=new Planitem();
    $planitem_fields=$pl->getCMSFields_forPopup($parentid);
    $kurs_field = new DataObjectManager(
    $this,
    'Kurse',
    'Planitem',
    array('Kursname.Name'=>'Titel/Name','date'=>'Datum','start'=>'Start','end'=>'Ende','level'=>'Level','Kurskategorien.cat'=>'Kategorie','Trainer.Name'=>'Trainer'),
    $planitem_fields,
    'Planitem.clubID='.$parentid,
    '',//,
    '
    Left Join Trainer ON "Planitem.trainerID=Trainer.ID"
    Left Join Kursname "Planitem.kursnameID=Kursname.ID"
    Left Join Kurskategorien ON "Planitem.kurskategorienID=Kurskategorien.ID"
    '
    );

    All fields which came from a joined table. like "Title/Name", "Kategorie" and "Trainer" can't be sorted in the backend.
    The table header field has no link. The other fields sort normal. Setting a default sort at one of these fields doenst work either. (without error)

    Any hints ?

    TIA
    Rufinus

  • UncleCheese
    Avatar
    4052 Posts

    Re: DataObjectManager unable to sort joined Fields ? Link to this post

    Can you confirm that this bug does or does not work when using a ComplexTableField in lieu of a DataObjectManager? Thanks.

    Also, you might want to clean up your code before posting it. We try to keep a family-friendly atmosphere in the SS forums.

  • Rufinus
    Avatar
    Community Member
    6 Posts

    Re: DataObjectManager unable to sort joined Fields ? Link to this post

    Hi,

    when i use ComplexTableField instead of DataObjectManager i get the table but no links in header column for sorting. (dont know if this is normal or not, never used ComplexTableField)

    Funny enough the links in CTF are working, but are not loaded where they should be. eg. paging next displays the table on a new site, with no SS styles.

    tia
    Rufinus

    PS: sorry, i edited the post. this was for debuging purpose only, and it seems i have forgot to remove it from my code to.

  • Rufinus
    Avatar
    Community Member
    6 Posts

    Re: DataObjectManager unable to sort joined Fields ? Link to this post

    Any idea UncleCheese ?

  • UncleCheese
    Avatar
    4052 Posts

    Re: DataObjectManager unable to sort joined Fields ? Link to this post

    I've been trying to replicate your use case, but I'm having a hard time, mostly because I've never used a join clause in a DOM or CTF field. The error I'm getting is that the joined table is creating an unknown field SQL error. Use this as an example.

    Join clause:
    "LEFT JOIN File ON File.ID = MyPage.DocumentID"

    My headers array:

    array(
    'PageField1' => 'Some field on my page',
    'PageField2' => 'Another field on my page',
    'File.Title' => 'File title'
    );

    Results in error "Method File() does not exist on MyPage"

    If I change that to just 'File' => 'File title' then I get "Unknown column File on MyPage";

    What I'm wondering is, do you already have the named relations for Trainer, Kursname, and Kurskategorien? Because Silverstripe will automatically look for RelationName.Field when using that syntax in your headers array. That is, if your page is set up like:

    $has_one ('Trainer' => 'TrainerObject')

    Then putting "Trainer.Name" in your headers array will work magically, with no need to use a join clause.

    Could you clarify?

  • monkee
    Avatar
    Community Member
    12 Posts

    Re: DataObjectManager unable to sort joined Fields ? Link to this post

    > $has_one ('Trainer' => 'TrainerObject')
    > Then putting "Trainer.Name" in your headers array will work magically, with no need to use a join clause.

    Thx, i was not aware of that.

    Like this Columns get filled correctly... but are no more sortable (sadly). Any Idea how to do that?

    Another Way is to include getters in the Dataobject Class:

    public function getAuthorName() {
          
       $author = $this->Author(); // from $has_one member...
       $author = $var->getField('Surname').", ".$var->getField('FirstName');
       
    return $author;
    }

    which will work to (using 'AuthorName' in the dataobjectmanager Headings array).
    like this it seems to be sortable in the table, but clicking on it fails with a wrong SQL Statement....

    ...ORDER BY AuthorName ASC LIMIT 10 OFFSET 0 Unknown column 'AuthorName' in 'order clause'

    Obviously it takes AuthorName as a normal db field, and not as a has_one relation
    how to get sort working?

    thanks a lot in advance

  • micahsheets
    Avatar
    Community Member
    160 Posts

    Re: DataObjectManager unable to sort joined Fields ? Link to this post

    Hello,

    I am needing to set a default sort for a DOM where the DataObjects displayed need to be sorted by the order of another set of DataObjects that are related through another DataObject. This seems complex I know but I have it working in ComplexTableField through the use of two JOIN tables. However when I change ComplexTableField to DataObjectManager I get the default sort that DOM uses if nothing is put into the Sort param. I know that DOM is not going to be used in SS 3 but until 3 is completely stable with a release version I won't be able to use it on client sites. I would appreciate any help on this I can get. The DOM I am using was downloaded from github about a month ago. Has this issue been fixed since then?

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