public function getAverage($objectTo) { if (!is_object($objectTo)) { throw new Exception('the first argument must be an object'); } $to_table = (string) $objectTo->db()->table; $to_id = (int) $objectTo->id; return Model::Notation()->where(['to_table', '=', $to_table])->where(['to_id', '=', $to_id])->avg('note'); }