rails-sqlserver / activerecord-sqlserver-adapter

SQL Server Adapter For Rails
MIT License
968 stars 558 forks source link

Composite Primary Keys not being recognised #1147

Closed defsdoor closed 5 months ago

defsdoor commented 5 months ago

Issue

Composite primary keys on rails 7.1 do not appear to be recognised.

Actual behavior

On a table with a (determined) primary key of [:OR20001, :OR20021], queries include the following column - which is the 2 primary keys -

EXEC sp_executesql N'SELECT OR200100.*, calculated_order_value , [OR200100].["OR20001", "OR20021"] AS t0_r0,

and raise this error -

ActiveRecord::StatementInvalid: TinyTds::Error: Invalid column name '"OR20001", "OR20021"'.
from /home/andy/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-sqlserver-adapter-7.1.1/lib/active_record/connection_adapters/sqlserver/database_statements.rb:416:in `each'
Caused by TinyTds::Error: Invalid column name '"OR20001", "OR20021"'.
from /home/andy/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-sqlserver-adapter-7.1.1/lib/active_record/connection_adapters/sqlserver/database_statements.rb:416:in `each'

Details

aidanharan commented 5 months ago

The CI test suite includes composite key tests so I'm not sure what is causing the issue.

Could you provide a test case (https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/How-to-report-a-bug#minimal-reproducible-script) so that I can recreate it myself.

defsdoor commented 5 months ago

Hi - sorry for being slow coming back to this. I'm embarrassed to say I cannot replicate it now - everything seems to be ok so I will close this immediately :o