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.

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

Filters and sorting when getting data through a relation

Go to End

3 Posts   1465 Views


Community Member, 26 Posts

3 April 2010 at 3:33pm

Hi there,

If I have a class that has a relation to another class and want to retrieve a DatabaObjectSet through the relation, can I also use filtering and sorting in the method call. For example:

Class myClass extends Page {

static $has_many = array { 'Students' => 'Student'; }
$mySeniorStudents = $this->Students('LasttName ASC', 'Age > 16');

I couldn't find any docs on this but I guess I'm trying to find something similar to the DataObject::get($obj, $filter, $sort, $join, $limit) method. If there is documentation, can you pls. provide the url?



Community Member, 253 Posts

4 April 2010 at 12:02pm

Edited: 04/04/2010 12:16pm

Yer, this is one of those 'hidden Gems'. I don't think it is documented.

But it is important to note that this returns a ComponentSet not a DataObjectSet

PS: it is hinted at here:


Community Member, 26 Posts

4 April 2010 at 1:40pm

thanks Pigeon!