s this code safe ?
$fields = array(
"services.*",
'pricings.term',
'packages.id' => "packages_id",
'package_group.package_group_id' => "filled_package_group_id",
'packages.name',
'contacts.company' => "client_company"
);
$this->Record->select($fields)->
from("services")->
innerJoin("package_pricing", "package_pricing.id", "=", "services.pricing_id", false)->
innerJoin("pricings", "pricings.id", "=", "package_pricing.pricing_id", false)->
innerJoin("packages", "packages.id", "=", "package_pricing.package_id", false)->
innerJoin("package_group", "package_group.package_id", "=", "packages.id", false)->
innerJoin("clients", "services.client_id", "=", "clients.id", false)->
innerJoin("client_groups", "client_groups.id", "=", "clients.client_group_id", false)->
on("contacts.contact_type", "=", "primary")->
innerJoin("contacts", "contacts.client_id", "=", "clients.id", false);
// Filter on client ID
if ($service_id != null)
$this->Record->where("services.id", "=", $service_id);
$this->Record->where("services.status", "!=", "canceled")->
where("services.package_group_id", "=", null);
// Ensure only fetching records for the current company
$this->Record->where("client_groups.company_id", "=", Configure::get("Blesta.company_id"));
$services = $this->Record->
fetchAll();
foreach ($services as $service)
$this->Record->where("services.id", "=", $service->id)->update("services", array('package_group_id' => $service->filled_package_group_id));