【发布时间】:2019-05-18 20:16:57
【问题描述】:
我有以下型号:
Table "public.models"
Column | Type | Collation | Nullable | Default
----------------------+-----------------------------+-----------+----------+---------------------------------------------
id | bigint | | not null | nextval('models_id_seq'::regclass)
research_provider_id | bigint | | not null |
covered_company_id | bigint | | not null |
publication_date | timestamp without time zone | | not null |
created_at | timestamp without time zone | | not null |
updated_at | timestamp without time zone | | not null |
insights_id | bigint | | not null | nextval('models_insights_id_seq'::regclass)
Indexes:
"models_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
"fk_rails_22d32db7ac" FOREIGN KEY (covered_company_id) REFERENCES companies(id)
"fk_rails_3a764bb9c1" FOREIGN KEY (research_provider_id) REFERENCES companies(id)
Referenced by:
TABLE "model_product_groups" CONSTRAINT "fk_rails_1866a14ba0" FOREIGN KEY (model_id) REFERENCES models(id)
TABLE "model_analysts" CONSTRAINT "fk_rails_c7730c705b" FOREIGN KEY (model_id) REFERENCES models(id)
我正在使用 ActiveRecord 创建对象,其中:
Model.new(
# insights_id:
research_provider_id: company.id,
covered_company_id: covered_company_id,
publication_date: Time.current - rand(1..20).day,
......
)
我应该将什么值传递给insights_id 以使用models_insights_id_seq 序列?试过DEFAULT,没有传递任何东西,都无法使用序列,即进行activerecord-import生成nextval('public.models_insights_id_seq')
注意:这个问题是要指示activerecord-import 为insights_id 列生成nextval('public.models_insights_id_seq'),而不是使用ActiveRecord 来获取序列下一个值。
【问题讨论】:
-
@AlexeySuslyakov 不同的场景,activerecord-import 用于填充大量数据,这也不是获取序列值,而是指示activerecord-import 生成正确的SQL。
-
哦,知道了。那么对不起
标签: ruby-on-rails ruby activerecord-import