rails-sqlserver/activerecord-sqlserver-adapter — Issue #135: Invalid generated SQL for DELETE with INNER JOIN
Author: jpzwarte
Created: 2011-10-24 13:12:12+00:00
State: open

The following Rails code generates the SQL query below that. The problem is that SQLServer doesn't accept the query, claiming it has an invalid syntax for the INNER JOIN.

Lms::Result.joins(:course).where(course: { uniqueid: course_id }).delete_all

DELETE FROM [lr] INNER JOIN [course] ON [course].[id] = [lr].[courseid] WHERE [course].[uniqueid] = N'1234'

It's a legacy database, so that's why the schema doesn't follow rails conventions.

The error returned is:

TinyTds::Error: Incorrect syntax near the keyword 'INNER'.: DELETE FROM [lr] INNER JOIN [course] ON [course].[id] = [lr].[courseid] WHERE [course].[uniqueid] = N'1234'

Running in the SMS given the same result.