XF 2.2 Avoiding having to do foreach with finder?

Dannymh

Active member
I just converted a query over to finder and the query works all but one thing, it puts the indexed ID as the array key rather than assigning these as 0+

so I would expect a results of

Code:
$finder->0>whatever

instead what it appears to do is us the ID

Code:
$finder->79->whatever
$finder->14->whatever

that works well if I am just going to loop through those results, however in my results for this I am looking at specific key values which would look something like

Code:
if($finder->0->whatever !="whatIwant")
{
//we want to grab 3rd item in the list because it has to exist there
$whatIwant = $finder->2->whatever;
}

Super simple version but I was hoping to traverse the results array by a location but if it takes the ID I can't do that.

Did I miss something?

My Finder looks like
Code:
 $highamount =  $this->finder('ST\Ledger:Amounts')
        ->where('thread_id', '=', $ledger->thread_id)
        ->order('max_amount', 'DESC')->order('input_time', 'ASC')
        ->fetch();
 
You could use slice to get a collection with the specific item:
PHP:
$results = $finder->fetch();
$containsThird = $results->slice(2, 1);
$third = $containsThird->first();
 
You could use slice to get a collection with the specific item:
PHP:
$results = $finder->fetch();
$containsThird = $results->slice(2, 1);
$third = $containsThird->first();
Thank you this is helpful. Also thanks for your video series in building with XF, really good man appreciate it
 
Top Bottom