繁体   English   中英

向数据库添加新记录时如何避免包含 OUTPUT INSERTED

[英]How to avoid includeing OUTPUT INSERTED when adding a new record to database

我在 Ruby on Rails 应用程序中使用 ActiveRecord gem。 我执行此命令以将新记录保存到我的数据库中:

Attachment.craete({IdAttachment: id , Name: name, Size: params[:file].size, UploadDate: DateTime.now })

由于我的表包含触发器,因此出现此错误:

ActiveRecord::StatementInvalid(TinyTds::Error:如果语句包含没有 INTO 子句的 OUTPUT 子句,则 DML 语句的目标表“附件”不能有任何启用的触发器。):

检查 activerecord 自动生成的 sql 查询,查询包含“OUTPUT INSERTED”,这是问题的原因。 有什么办法可以避免在查询中包含“OUTPUT INSERTED”吗?

EXEC sp_executesql N'INSERT INTO [Attachment] 
([IdAttachment], [Title], [IdVch], [IdForm], [Name], [Size], [UploadDate], [IdUser])
OUTPUT INSERTED.[IdAttachment] 
VALUES (@0, @1, @2, @3, @4, @5, @6, @7)', 
N'@0 int, @1 nvarchar(max), @2 int, @3 int, @4 nvarchar(max), @5 float, @6 datetime, @7 int', @0 = 21007, @1 = NULL, @2 = NULL, @3 = NULL, @4 = N'uf21007_pic.jpg', @5 = 87041.0, @6 = '11-20-2022 13:23:20.706', @7 = NULL

来自https://github.com/rails-sqlserver/activerecord-sqlserver-adapter#identity-inserts-with-triggers

  adapter = ActiveRecord::ConnectionAdapters::SQLServerAdapter

    # Will assume `bigint` as the id key temp table type.
    adapter.exclude_output_inserted_table_names['my_table_name'] = true
    
    # Explicitly set the data type for the temporary key table.
    adapter.exclude_output_inserted_table_names['my_uuid_table_name'] = 'uniqueidentifier'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM