在 rails 个固定装置中使用自定义外键标记引用

Label references with custom foreign keys in rails fixtures

我有一个 lists class 和一个自定义的 foreign_key

class List < ActiveRecord::Base
    belongs_to :user, foreign_key: 'author_id'

创建 table 添加引用和外键如下

add_reference :lists, :author, index: true
add_foreign_key :lists, :users, column: :author_id

问题是,在我的固定装置中,我尝试使用标签引用,但我一直收到 SQL 异常
table lists 没有名为 author

的列
lists.yml

list1:
    name: topchartsyea
    author: dude1

有什么想法吗?在使用像这样的自定义外键时甚至可以使用标签引用吗?

使用 rails 4.2.0

我认为您的问题是您在将关系命名为 user 后尝试使用 author。如果你想让你的灯具像那样工作,那么我认为这应该解决它:

class List < ActiveRecord::Base
  belongs_to :author, class_name: 'User', foreign_key: :author_id