0

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?

potashin
  • 44,205
  • 11
  • 83
  • 107
Thermatix
  • 2,757
  • 21
  • 51
  • 1
    Are you certain the back-ticks are the problem, and not the `WHERE ('npt_teams.id' IN (1))`? Back-ticks shouldn't cause the issue - the single-quotes, however, should. – Siyual Jun 17 '16 at 12:49
  • ok, then how do I get sequel to generate it without quotes then? – Thermatix Jun 17 '16 at 12:55
  • Can't help you there, sadly. I don't know anything about `sequel`. – Siyual Jun 17 '16 at 12:56

1 Answers1

1

You should try something like this:

.where(:npt_teams__id => [team.id])
potashin
  • 44,205
  • 11
  • 83
  • 107
  • That worked, changing the bit to this also worked: `.where("npt_teams.id IN (#{team.id})")`.Although it now causes the script to hang, it works in mysqlworkbench... – Thermatix Jun 17 '16 at 13:07