我的印象是,Rails不應該在數據庫中定義任何依賴關係,而只是使用has_many和belongs_to來定義關係。但是,我正在通過導軌指南,它具有以下內容。Rails理論 - 無數據庫依賴關係?
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.string :commenter
t.text :body
t.references :post
t.timestamps
end
add_index :comments, :post_id
end
end
我以爲這樣不好... ...?我試圖做一些類似於註釋字段的事情,每次調用show方法時都會創建一個新實例,但是我認爲沒有這些「引用」和「add_index」,它不會將post_id存儲在註釋行中。
有一個很好的消滅這個所有軟件截屏 - https://www.destroyallsoftware.com/screencasts/catalog/where-correctness-is-enforced – 2013-02-12 20:46:34