Is there a $query->has(‘field’) method so that I can verify if that field exists in the query before the Table::beforeFind method tries to order the records of that table?
This is the code for beforeFind method in AffiliatesTable class:
public function beforeFind(EventInterface $event, Query $query, ArrayObject $options, $primary)
{
$event->stopPropagation();
$query->order(["Affiliates.lastname", "Affiliates.firstname"]);
return;
}
I don’t believe that at this time anything about the schema has been looked at. There is a way to look at what associations are defined for the table where this call is happening, so you might be able to use that to determine (indirectly, through some new functionality you’d need to write) whether the “Affiliates” association exists. But even that wouldn’t guarantee that it’s been contained in the current query.