Jump to:

3372 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Grouping by CategoryName and not CategoryID

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

Page: 1
Go to End
Author Topic: 224 Views
  • ShadeFrozen
    Avatar
    Community Member
    10 Posts

    Grouping by CategoryName and not CategoryID Link to this post

    HI;

    I have a category holder page with a series of category pages set up underneath it, and within each category page are links (as dataobjects). What I want is to get all links from all categories and sort by category. Currently I can do it but I can only sort by CategoryLinkID. Code is as follows:

    http://pastie.org/8226446

    Now, instead of sorting by the LinksCategoryID which is all I have available as far as the category reference is concerned, I wish to get the URLSegment from LinksCategory where the ID is the same as the LinksCategoryID and insert it into the main link record.

    I'm sure there is an easy way to do this but I haven't figured it out yet. Any ideas?

  • ShadeFrozen
    Avatar
    Community Member
    10 Posts

    Re: Grouping by CategoryName and not CategoryID Link to this post

    I think I know what I need to do, just not how to do it.

    class CategoryLink extends DataObject {

    static $plural_name = 'Category Links';
    static $singular_name = 'Category Link';

    //Relations
    static $db = array (
    'Name' => 'Varchar(100)',
    'URL' => 'Varchar(100)',
    'CategoryName' => 'Varchar(100) // <-- need to add this field to the array
    );

    static $has_one = array (
    'LinksCategory' => 'LinksCategory',//link can only have one category
    'LinkImage' => 'Image'
    );

    public function getCMSFields_forPopup() {
    return new FieldSet(
    new TextField('Name','Link Name'),
    new TextField('URL','Web Address'),
    new FileIFrameField('LinkImage'),

    //<-- and in here add LinksCategory.Title as a hidden field to the record but only the first time its created
    //something like hidden TextField('CategoryName', $LinksCategory.Title)
    //then I can do the sort on this
    )
    );
    }

    Yes, no, maybe?

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