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.

Data Model Questions /

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

Grouping by CategoryName and not CategoryID


Go to End


2 Posts   1076 Views

Avatar
ShadeFrozen

Community Member, 10 Posts

11 August 2013 at 12:41am

Edited: 11/08/2013 8:54pm

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?

Avatar
ShadeFrozen

Community Member, 10 Posts

12 August 2013 at 12:01am

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?