【发布时间】:2018-07-23 22:58:42
【问题描述】:
以下:
class Author < ApplicationRecord
has_many :books
end
class Book < ApplicationRecord
belongs_to :author
end
如果我有电话:
book.author.method1
是否可以在方法 1 中获取书籍 ID(或任何对象的数据)? (无需作为参数传入)
【问题讨论】:
-
method1的本质是什么?也许让method1成为book上的方法而不是author是有意义的。
标签: ruby-on-rails activerecord ruby-on-rails-5