Thermatix Thermatix - 10 months ago 28
Ruby Question

Get sequel generated sql to generate field names without backticks

I have the following query written in SQL:

Select *
From npt_articles
Inner Join npt_authors
Inner Join users
Inner Join npt_teams
Where In (1)

and the following sql generated by the sequel gem:

FROM `npt_articles`
INNER JOIN `npt_authors`
INNER JOIN `users`
INNER JOIN `npt_teams`
WHERE ('' IN (1))

The first returns results, the second one doesn't, if I remove the back-ticks then the second then it generates the same result as the first.

This is the code that generates the second sql:

team_articles = user.npt_teams.to_a.inject({}) {|arts,team|
arts.merge({ =>
NptArticle.join(:npt_authors).join(:users).join(:npt_teams).where('' => []).to_a.uniq})

How do I get the query generated without backticks?


You should try something like this:

.where(:npt_teams__id => [])