1
class User < ActiveRecord::Base
has_many :books
has_many :book_users
has_many :books, :through => :book_users
end
class Book < ActiveRecord::Base
belongs_to :user
has_many :book_users
has_many :users, :through => :book_users
end
的用戶可以寫很多書 一本書只能屬於一個用戶 的用戶可以將不同書籍 讀者的書可以由不同的用戶讀取的Rails 3個聯
User.books
應該給我的用戶已經寫
User.books_read
應該給我的書的書,是由該用戶讀取
這是怎麼做到的?
第二個問題,從用戶中刪除book_read最簡單的方法是什麼? 我的意思是
User.method_name(book_id) # what's the method name ?