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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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   1472 Views

Avatar
aragonne

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:

<code>
Class myClass extends Page {

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

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?

thanks!
Steve

Avatar
dhensby

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: http://doc.silverstripe.org/doku.php?id=datamodel#custom_relation_getters

Avatar
aragonne

Community Member, 26 Posts

4 April 2010 at 1:40pm

thanks Pigeon!

Steve