I'm currently trying to run a subquery within a JOIN but $this->db->join() keeps breaking the query - it seems it is trying to protect field/table names. It ends up adding backticks to SELECTs in the subquery. It'd be nice if AR would support subqueries or if I could tell it to not protect fields by passing an additional parameter.
In this query for example, AR adds back ticks to the SELECT present within the join - which of course breaks the query
products AS p
images AS i
ON i.image_id =
( SELECT image_id
FROM products_images AS pi
WHERE pi.product_id = p.product_id
ORDER BY `order` ASC --- or DESC
I'm not too familiar with github -- could someone please make a request to include a fourth parameter that skips the _protect_identifiers() of $cond? Link to lines That way, I believe, we could do a bit more complex joins while still enjoying the benefits of AR.
Similar bug report here: #610