gpt4 book ai didi

ruby - 如何在没有 rails 的情况下禁用 activerecord-oracle_enhanced-adapter 中的序列?

转载 作者:数据小太阳 更新时间:2023-10-29 07:36:20 25 4
gpt4 key购买 nike

我只使用 ActiveRecord 对遗留 Oracle 数据库进行一些开发。我的适配器是 activerecord-oracle_enhanced-adapter ( https://github.com/rsim/oracle-enhanced )。所以我不想让 AR 处理主键生成。如何禁用序列生成的主键?

class User < Activied::Base
self.table_name = "users"
self.primary_key = "user_id"
end

user = User.new
user.save

然后我得到了错误:

stmt.c:230:in oci8lib_191.so: ORA-02289: sequence does not exist (OCIError)

当我将代码更改为

class User < ActiveRecord::Base
self.table_name = 'users'
self.primary_key = "user_id"
self.sequence_name = nil
end

我得到另一个错误:

stmt.c:230:in oci8lib_191.so: ORA-00936: missing expression (OCIError)

那么有没有人知道如何手动管理主键呢?我只想做一些简单的插入。

谢谢

最佳答案

也许为时已晚,但最终我找到了答案。很快:

self.sequence_name = :autogenerated

来自源码注释here :

Usage notes:

# * Key generation assumes a "${table_name}_seq" sequence is available
# for all tables; the sequence name can be changed using
# ActiveRecord::Base.set_sequence_name. When using Migrations, these
# sequences are created automatically.

# ***Use set_sequence_name :autogenerated **** with legacy tables that have
# triggers that populate primary keys automatically.**

关于ruby - 如何在没有 rails 的情况下禁用 activerecord-oracle_enhanced-adapter 中的序列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15737290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com