Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
RS71 opened this Issue · 4 comments

3 participants

@RS71

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.

@RS71

In this query for example, AR adds back ticks to the SELECT present within the join - which of course breaks the query

SELECT 
    p.*
  , i.thumbnail
FROM 
    products AS p
  LEFT JOIN
    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
         )
@RS71

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.

@uzsolt

Similar bug report here: #610

@narfbg
Owner
@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.