Count on a Polymorphic Relationship with criteria

Posted 3 years ago by domioanna

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.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.