Compare parent data with relationship data

Posted 1 year ago by dlebedef

Here is my case:

  • Model Order
  • Model ConstructionSite
  • Model WorkingHours

An Order has one ConstructionSite which in turn can have multiple WorkingHours.

In my table Order I have a column "installation_planned_hours" and in my table WorkingHours I have a column "worked_hours".

What is the best and more efficient way to retrieve all Orders which total of "worked_hours" (remember Order->ConstructionSite->WorkingHours) is at least 80% of the "installation_planned_hours"?

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