gpt4 book ai didi

ruby-on-rails - 在 rails 中具有关联的 fixture

转载 作者:行者123 更新时间:2023-12-04 21:50:40 26 4
gpt4 key购买 nike

我在 Fixtures 中遇到了一些问题

我有模特优势和善良

优势.rb

belongs_to :kind

种类.rb
 has_many :advantages

优势.yml

1.
id: 1
title: something
kind: apple
kind_id: 1

2.
id: 2
title: somethjin
kind: orange
kind_id: 2

种类.yml
apple:
id: 1
name: apple
orange:
id: 2
name: orange

我正在尝试将关联带到这里,因为 kind_id 带有一些垃圾值

所以我确实喜欢

种类.yml
apple:
name: apple
orange:
name: orange

并在优势.yml

某物:
title: something
kind: apple

某物
title: somethjin
kind: orange

但它没有用

如何解决这个问题

最佳答案

像这样尝试但不确定:

种类.yml
苹果:
编号:1
名称:'名称1'
橘子:
编号:2
名称:'name2'

优势.yml
广告1:
编号:1
标题:'标题1'
种类:苹果

关于ruby-on-rails - 在 rails 中具有关联的 fixture ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5233306/

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