dimanche 3 juillet 2016

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      npt_teams.id In (1)

and the following sql generated by the sequel gem:

SELECT     * 
FROM       `npt_articles` 
INNER JOIN `npt_authors` 
INNER JOIN `users` 
INNER JOIN `npt_teams` 
WHERE      ('npt_teams.id' 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({ team.name =>
    NptArticle.join(:npt_authors).join(:users).join(:npt_teams).where('npt_teams.id' => [team.id]).to_a.uniq})
  }

How do I get the query generated without backticks?

Aucun commentaire:

Enregistrer un commentaire