XF 2.2 Finder: picking one value of a to_many relation for sorting..

Newsman

Member
Hey!

I was playing around with the Finder and been wondering: how can I select just one specific value of a to_many relation, for example the very first value?

In the template sytax, this is no problem: $Threads|first gives you the first element of $Threads. Is there an equivalent for the Finder that just picks one value of a to_many relation?

My custom content can have threads tagged to them, and I want to sort the order of an array collection with said custom content by the most recent thread.

Cheers and thanks for any input!
 
You can eager-load (join) a single record by its key (the key column set on the relation definition):

PHP:
$finder->with('SomeRelation|keyValue');

You can lazy-load records by getting the relation finder and doing whatever you want:
PHP:
$relationFinder = $entity->getRelationFinder('SomeRelation');
$relation = $relationFinder->order('some_thing')->fetchOne();
 
Back
Top Bottom