# Type of associated data - CakePHP4

**URL:** <https://discourse.cakephp.org/t/type-of-associated-data-cakephp4/9774>\
**Category:** Need Help\
**Created:** [October 5, 2021, 11:28am UTC](https://discourse.cakephp.org/t/type-of-associated-data-cakephp4/9774 "2021-10-05T11:28:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cowtan](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@cowtan](https://discourse.cakephp.org/u/cowtan)\
**Post date:** [October 5, 2021, 11:28am UTC](https://discourse.cakephp.org/t/type-of-associated-data-cakephp4/9774/1 "2021-10-05T11:28:44Z")

</div>

I’m wanting to find the maximum and minimum values in some associated data (via a one to many relationship). I thought it might be possible to use the max() and min() functions in the view eg

```auto
$min_price = $thing->associated_things->min('price');

```

But I discovered that the associated data is arriving as an array rather than an entity on which I can use max() or min().

The association is set-up in the model as -

```auto
$this->hasMany('AssociatedThings', [
       'foreignKey' => 'thing_id',
]);

```

I’m then using contain to pass on the association to the view -

```auto
$things = $this->$Things->find('all',['contain' => 'AssociatedThings']);

```

I’m getting round this by iterating on the array in the view to find the max and min but it’s a bit clunky. Is there a better way of doing this and is associated data defined in this way always an array?
