2014-01-07 34 views
0

我是Postgres的新手,在測試博客類型應用程序的銷燬操作時出現此錯誤。看起來問題在於works而不是work在給定作者被破壞時被調用 - 因爲它被複數化,但我不確定這是爲什麼。依賴:使用postgresql銷燬拋出錯誤

Author.rb 
has_many :works, :dependent => :destroy 

錯誤:

AuthorsController::destroy#test_0001_deletes the author: 
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column works.author_id does not exist 
LINE 1: SELECT "works".* FROM "works" WHERE "works"."author_id" = $... 
              ^
: SELECT "works".* FROM "works" WHERE "works"."author_id" = $1 ORDER BY works.id ASC 

測試:

it "deletes the author" do 
    assert_difference 'Author.count', -1 do 
    delete :destroy, :id => author.id 
    end 
end 

控制器:

def destroy 
    @author.destroy 
    redirect_to authors_path 
end 

回答

2

是Postgres的抱怨的問題是,它無法找到列在你身上叫做author_id r works表,因此,對於給定的Author,將無法找到對應的works

如果您還沒有,則需要添加一個遷移以將author_id列添加到Work

+0

就是這樣...感覺有點蠢:p謝謝! – dax