Jump to:

23478 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Splitting DataObject using ModelAdmin

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: 563 Views
  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Splitting DataObject using ModelAdmin Link to this post

    Hello everyone,

    I have a DataObject (named Extra) that has very much outgrown it's original purpuse and has tons of entries (where it was supposed to have less than a hundred, but now is many thousands).

    There is a enum type field and effective dates (and a couple of other "filters").

    Currently it is one entry in the managed_models in ModelAdmin, but I keep getting asked to split it up.

    It would be easier to modify the presentation of this within ModelAdmin rather than the code that is filled with DataObject::get_by_id('Extra'), $somedataobject->ExtraID and many other things.

    So my question is how can I add two entries into the managed_models for Extra based on the type of Extra? or is there another way someone can think of to split this dataobject up for easier access/editting?

    All help appreciated!

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Splitting DataObject using ModelAdmin Link to this post

    Answer to my own question...

    Create several ModelAdmin's - set and override the collection controller and add this function...

    function getSearchQuery($searchCriteria){
       $query = parent::getSearchQuery($searchCriteria);
       $query->where[] = "Type='Cash Voucher'"; //<-- changing for each type of ModelAdmin
       return $query;
    }

    Then to handle the increased number of menu items...

    https://github.com/ajshort/silverstripe-groupedcmsmenu

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Splitting DataObject using ModelAdmin Link to this post

    Nice! Couldn't help thinking about it, and all the extra menuitems seemed like an obstacle to me. But then I never knew about the ajshort dropdown menu To complete things: how do you handle new items getting the correct value for each type? A hidden field I guess?

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Splitting DataObject using ModelAdmin Link to this post

    how do you handle new items getting the correct value for each type? A hidden field I guess?

    That part is fine - there are only 3/4 "Types" in the enum that need to be split out. So creating an individual ModelAdmin with a hardcoded extra where clause added in getSearchQuery is fine.

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