Open budiljak opened 3 days ago
@budiljak Could you provide a test case (https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/How-to-report-a-bug) to demonstrate the issue?
Hi @aidanharan. As the bug is pretty obvious I thought you won't need the test case. But I understand how tiring it is to chase bugs that aren't bugs. Here's the testcase.
Cheers, Ben
Fixtures for Rails tests cannot be created if an ActiveRecord model is created on a view instead of a table and the tables primary key is an IDENTITY column. While creating fixtures for such a model the rails test environment needs to turn on IDENTITY_INSERT. This fails for views as it has to be executed on the underlying table.
The error message is:
IDENTITY_INSERT could not be turned OFF for table [xyz]
([xyz] would be the name of the view).
Expected behavior
Should call "SET IDENTITY_INSERT" on the underlying table.
Actual behavior
Calls "SET IDENTITY_INSERT" on the view the model is based on.
Solution
See
def set_identity_insert(table_name, conn, enable)
(lib/active_record/connection_adapters/sqlserver/database_statements.rb line 303)table_name
is view name here.