我有三个STI课程,我想为每个课程加载灯具:
Employee
Admin < Employee
OtherEmployee < Employee
我的test_helper文件有fixtures :all
并且灯具位于:
employees.yml
admins.yml
other_employees.yml
但只有来自other_employees.yml
的数据被加载到数据库中。知道为什么或如何解决这个问题?
赛程:
#employees.yml
one:
id: 1
name: Name1
full_name: FName1
type: Admin
two:
name: Name2
full_name: FName2
type: Admin
three:
name: Name3
full_name: FName3
type: OtherEmployee
#admins.yml
adminone:
name: Admin1
full_name: FAdmin1
type: Admin
admintwo:
name: Admin2
full_name: FAdmin2
type: Admin
#other_employees.yml
oeone:
name: Oemp1
full_name: FOemp1
type: OtherEmployee
oetwo:
name: Oemp2
full_name: FOemp2
type: OtherEmployee
答案 0 :(得分:0)
您使用的是哪个版本的Rails?看起来这是一个错误,并在Rails 5和4.2中得到修复
https://github.com/rails/rails/issues/18492
最后一条评论中也有一些信息可能会有所帮助。
https://github.com/rails/rails/issues/18492#issuecomment-218479248
对于仍然遇到此问题的任何人,您需要添加一个类型 属性到你的灯具,它代表你的STI属性 模型。对于提供的示例,这将是:
#teachers.yml presto: name: Test Teacher type: Teacher #students.yml testo: name: Test Person teacher: presto type: Student