2

how can I modify my propel query to get the same result as the following MySQL query ?

SELECT v.id,CONCAT_WS(" ",b.name,v.model) AS car_name
FROM vehicle v
JOIN account_vehicle av ON av.account_id=:uid
LEFT JOIN brands b ON b.id=v.manufacturer
WHERE av.vehicle_id=v.id

Right now i have something like that

$query = VehicleQuery::create('v')
->joinAccountVehicle('av')
->leftJoinBrands('b')
->select(array('v.Id', 'b.Name', 'v.Model'))
->where('av.VehicleId=v.Id')
->find();

How can i modify the propel use - to get the same result ? I'm having difficulties with the concat_ws function in propel. I've tried using the Criteria model - but I cant add the joined table (criteria requires TABLEPEER:COLUMN_NAME's and rejects my aliases)

Axel
  • 61
  • 1
  • 9
  • The following question could be helpful: [How to use MySQL functions in Propel](http://stackoverflow.com/a/260263/3182500). – ragol Jan 23 '14 at 10:51
  • hmmm populating objects also isn't the right way for this, when is use it - i loose all the benefits from using the active queries. – Axel Jan 23 '14 at 11:11

1 Answers1

1

Try something like this:

$query = VehicleQuery::create('v')
->joinAccountVehicle('av')
->leftJoinBrands('b')
->select(array('v.Id', 'b.Name', 'v.Model','CONCAT_WS(" ",b.name,v.model) AS car_name'))
->where('av.VehicleId=v.Id')
->find();
Suresh Kamrushi
  • 15,627
  • 13
  • 75
  • 90
  • check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS "CONCAT_WS(" ",b.name,v.model) AS car_name" FROM `vehicle` INNER JOIN `accoun' at line 1' so as you can see - this concat_ws is treated like an alias – Axel Jan 23 '14 at 13:12