How to give contain data condition in current model data?

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

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

Thanks.

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

    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.

1 Like