# How to give contain data condition in current model data?

**URL:** <https://discourse.cakephp.org/t/how-to-give-contain-data-condition-in-current-model-data/2152>\
**Category:** Need Help\
**Created:** [February 23, 2017, 12:49pm UTC](https://discourse.cakephp.org/t/how-to-give-contain-data-condition-in-current-model-data/2152 "2017-02-23T12:49:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SATHISH](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@SATHISH](https://discourse.cakephp.org/u/SATHISH)\
**Post date:** [February 23, 2017, 12:49pm UTC](https://discourse.cakephp.org/t/how-to-give-contain-data-condition-in-current-model-data/2152/1 "2017-02-23T12:49:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shubhrajyoti](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/shubhrajyoti/32/544_2.png) [@shubhrajyoti](https://discourse.cakephp.org/u/shubhrajyoti)\
**Post date:** [February 25, 2017, 11:11am UTC](https://discourse.cakephp.org/t/how-to-give-contain-data-condition-in-current-model-data/2152/2 "2017-02-25T11:11:08Z")

</div>

```
$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

---

<div class="post-metadata">

**Author:** ![SATHISH](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@SATHISH](https://discourse.cakephp.org/u/SATHISH)\
**Post date:** [February 27, 2017, 4:46am UTC](https://discourse.cakephp.org/t/how-to-give-contain-data-condition-in-current-model-data/2152/3 "2017-02-27T04:46:52Z")

</div>

Thanks for your replay.
