take this, i use it and i can get the total services using the package X with option to filter per service status
public function getUsedServices($package_id, $service_status = null)
{
$this->Record->select('services.id')->from('package_pricing')->
innerJoin('services', 'services.pricing_id', '=', 'package_pricing.id', false)->
where('package_pricing.package_id', '=', $package_id);
if ($service_status) {
$this->Record->where('services.status', '=', $service_status);
}
return $this->Record->numResults();
}
you can use it as getUsedServices($package_id, 'active') to get total active services using the package X