# Field to count the number of objects in relation

**URL:** <https://discourse.cakephp.org/t/field-to-count-the-number-of-objects-in-relation/5754>\
**Category:** Need Help\
**Created:** [March 8, 2019, 1:35pm UTC](https://discourse.cakephp.org/t/field-to-count-the-number-of-objects-in-relation/5754 "2019-03-08T13:35:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![okelet](https://avatars.discourse-cdn.com/v4/letter/o/919ad9/32.png) [@okelet](https://discourse.cakephp.org/u/okelet)\
**Post date:** [March 8, 2019, 1:35pm UTC](https://discourse.cakephp.org/t/field-to-count-the-number-of-objects-in-relation/5754/1 "2019-03-08T13:35:32Z")

</div>

Hi all. I have been reading about [CounterCache behavior](https://book.cakephp.org/3.0/en/orm/behaviors/counter-cache.html), but it is not useful for me (“main” object is not edited frequently, and related objects are generated by a background process). I have an entity, that has a hasMany relation, and I want to have a field to show the number of objects in that relation. Can this be done using a virtual field? Is there any other approach? Thanks!

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [March 8, 2019, 4:52pm UTC](https://discourse.cakephp.org/t/field-to-count-the-number-of-objects-in-relation/5754/2 "2019-03-08T16:52:29Z")

</div>

It’s not clear to me why the background process wouldn’t be able to update the counter cache.
