gpt4 book ai didi

ruby-on-rails - 在 Rails 中指定一个空的或 nil fixture

转载 作者:行者123 更新时间:2023-12-02 15:42:54 25 4
gpt4 key购买 nike

我有 ff。我仅将其用于生成的 ID 的 ActiveRecord:

class SomeTable < ActiveRecord::Base
end

我认为可以通过以下方式为其指定固定装置:

one:

two:

我在其他灯具中将其称为:

other_one:
some_field: some value
some_table: one

但是当我运行测试时,我得到:

Fixture::FormatError: Bad data for SomeTable fixture named one (nil)

那么有人知道如何指定空的或零的固定装置吗?如果这不可能,则可以接受变通或替代解决方案。

最佳答案

如果您想将标签用作其他一些 fixture 文件中的外键,则不应显式设置 id。

# in users.yml
one: {}

two: {}

# now in posts.yml, this works:
one:
user: one

关于ruby-on-rails - 在 Rails 中指定一个空的或 nil fixture ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1467507/

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