我有一个联想:
一个作者有很多书;一本书有很多作者;
我需要使用:通过选项(通过一个名为“关系”的表,有两列名为“left_id”(用作author_id)和“right_id”(用于广告book_id);
class Relation < ActiveRecord::Base
belongs_to :books
belongs_to :authors
end
class Author < ActiveRecord::Base
has_many :relations, :foreign_key => 'left_id'
has_many :books, :through => :relations
end
在控制台中:
> author = Author.new
> author.books
# => Error: no such column: relations.book_id
那么,我如何将 'book_id' 指定为 'right_id'?(有没有像 'foreign_key' 这样的选项?)