Method MAX through ActiveRecord relations


Here is my relations:

-"server" BELONGS_TO "site"

-"site" HAS_MANY "contracts"

In a function of my class server, I want get the greatest subscription date defined in my contract. Here is what I do:


foreach ($this->site->contracts as $contract) {

    if ($contract->subscription_date>$subscription_date)



It works but it’s not very smart… Is there a way to simplify that?