XF 2.2 additional where clauses on em()->find?

Dannymh

Active member
I am unsure if this is possible or not, but with a call like

PHP:
em()->find('XF:Thread')
is it possible to build out the same as with a finder so for instance for it to look like

PHP:
em()->find('XF:Thread')
->where('thread_title', '=', 'Whatever')
->order('thread_id', 'ASC')

or should I just use a Finder here. This is just for cron task that I have going on.
 
find is designed to find a specific single entity based on its primary key, so it's not possible to chain additional methods.

finder is most appropriate if you wish to find one or more entities with various conditions.

But another option is findOne if you only want to select a single entity with different conditions.

PHP:
em()->findOne('XF:Thread', ['title' => 'Whatever'])

In this case, it will only return a single entity, and if the query matches multiple entities, it will select the first one only.
 
ok great thanks Chris.
I am just trying to be trickier than I need to be here, probably better to sacrifice one extra query since its in cron anyway than try to work too hard at what I am trying to do here
 
PHP:
$thread = \XF::finder('XF:Thread')
    ->where('thread_title', '=', 'Whatever')
    ->order('thread_id', 'ASC')
    ->fetchOne();
 
Top Bottom