Thanks @Phalcon.
After I posted this message, I continued my reading on the principal that I couldn't do what I wanted to do i.e. use the Models and the ::find() functions, and based on your answer thats what you're saying too.
As such I've come up with the following, which completes the query using the querybuilder:
$projects = $this->modelsManager->createBuilder()
->columns(array(
"Project.id",
"Project.title",
"IFNULL(SUM(ProjectOrders.design_costs + ProjectOrders.design_expenses + ProjectOrders.design_mileage + ProjectOrders.post_design_costs + ProjectOrders.post_design_expenses + ProjectOrders.post_design_mileage + ProjectOrders.equipment_costs + ProjectOrders.installation_costs), 0) as sumCosts",
"CONCAT(Director.forename, ' ', Director.surname) as director",
"CONCAT(Manager.forename, ' ', Manager.surname) as manager",
"Site.telephone",
"Site.fax",
"Address.city",
"Client.name",
"CONCAT(Contact.forename, ' ', Contact.surname) as contact",
"0 as percentage"
)
)
->from(array("Project" => "\\SPARCS\\PMS\\Models\\PmsProjects"))
->join("\\myApp\\PMS\\Models\\PmsProjectOrders", "ProjectOrders.project_id = Project.id", "ProjectOrders", "LEFT")
->join("\\myApp\\CRM\\Models\\CrmSites", "Site.id = Project.site_id", "Site")
->join("\\myApp\\CRM\\Models\\CrmClients", "Site.client_id = Client.id", "Client")
->join("\\myApp\\CRM\\Models\\CrmContacts", "Contact.id = Project.contact_id", "Contact")
->join("\\myApp\\common\\Models\\CoreAddresses", "Address.id = Site.address_id", "Address")
->join("\\myApp\\common\\Models\\SystemUsers", "Director.id = Project.director_id", "Director", "LEFT")
->join("\\myApp\\common\\Models\\SystemUsers", "Manager.id = Project.manager_id", "Manager", "LEFT")
->groupBy("Project.id")
->orderBy("Project.id DESC")
->getQuery()
->execute();
The question I now have is this: is there a better way?
The reason I'm asking is:
- I have to write out each join individually with namespaces
- I can no longer use:
{{ projects.contact.forename }}
to get to the contacts forename
At present this is getting me along, but i feel like there should be an easier way. I'm open to suggestions and comments.
Many thanks in advance.
UPDATE:
After some further reading and some testing, this appears to be the way to do this.