Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

domioanna's avatar

Count on a Polymorphic Relationship with criteria

Say I have a Strategy table which has a polymorphic relationship with 3 other tables of Strategy 1, Strategy 2 and Strategy 3.

I need to count how many records there are in just one of the linked tables (i.e. Strategy 2) that match a criteria, i.e. the value of a field is > 150.

I really can't get my head around how to do it.

Any ideas?

Just to give an idea of the relationships...

User HAS MANY Strategies

Strategies HAVE MANY "sub" strategies.

0 likes
0 replies

Please or to participate in this conversation.