如何使用嵌套列的with()方法和where()方法?

There is a structure like this:

Entity1 has many Entity2 that has many Entity3

I want to get all entities of Entity3 that are associated with one entity of Entity1.

In SQL it would be something like:

 SELECT Entity3.*
    FROM Entity3
    INNER JOIN Entity2 on Entitity3.entity2_id = Entity2.id
    INNER JOIN Entity1 on Entity2.entity1_id = Entity1.id
    WHERE
        Entity1.id = X;

I could find a way, as it follows:

$entities3 = Entity3::find()->joinWith(['entity2.entity1'])->where('entity2.entity1_id='.$entity1_id)->all();

In Entity1 model:

public function getEntities2()
{
     return $this->hasMany(Entity2::className(), ['id' => 'entity2_id']);
}

public function getEntities3()
{
     return $this->hasMany(Entity3::className(), ['id' => 'entity3_id'])->via('entities2');
}