Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Active Record breaking subqueries within JOINs - needs optional field/table protection #590

RS71 opened this Issue · 4 comments

3 participants


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

  , i.thumbnail
    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
           LIMIT 1

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

@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.