Search by foreign keys

Hello.

Can you tell if i can search by a foreign key with find() method ? Or i should create a custom query for that ?



83.4k

You can use a query builder for that:

$robots = $this->modelsManager->createBuilder()
                ->from('Robots')
                ->join('Parts')
                ->where('Parts.type <> "some-type"');


32.7k

Thank you. In my app i have to run complex queries, and i think i will choose to write them plain. What would be a good practice to run complex queries in models, without using directly the pdo ?

Now i have something like:

    $db = $this->getDI()->get('db')->getInternalHandler();
    $s_query = '...';
    $result  = $db->query($s_query);
    $result->setFetchMode(\PDO::FETCH_OBJ);

    return $result->fetchAll();

PS: I think it would be nice and helpful to have a section in the documentation, like "Good practices"