Iterate through associated Model in Entity

How can I access associated (belongsTo) entities in the (e.g.) entityGroup Entity? I wanted to write a function that iterates over all associated (belongsTo) entities and counts how many of which type are in any entityGroup Model. But I cannot find out how I access one Entity in the other linked one.

public function getAmount($type): int
    {

        $associatedEntities = $this->associatedEntities;
... 

I tried something like this code in the Entity Class but it returns Null.

You could use getSource to locate the table for the entity, then associations on that table object.

1 Like