How to give contain data condition in current model data?


I am using three models m1,m2,m3, I want get count of data based on the condition

            where( =    but m1  associated with m2 and m2 accociated with m3. 


$data = $this->find('all')
            ->contain(["M1" => ["M2"], "M3"])
            ->where([" ="])

    return $data;

you may try this. It’s for cakephp 3.0 +

Remember to set the relationship into the tables.php file of each table


Thanks for your replay.