2013-08-21 1 views
0

내 짧은 문제는 관련된 데이터를 삭제하려고 할 때 시스템이이를 업데이트하려고 시도하고 db에서 데이터를 삭제하지 않는 경우입니다.관련 데이터를 개체로 삭제 (업데이트하지 않음)

내 DB 스키마는

TBL입니다 스테이션 (ID, ...)

(ID, 이름, station_id)

내 모듈 associated_names TBL :

class Station 
has_many :associated_names, :inverse_of => :station 
end 
class AssociatedName 
has_one :station, inverse_of: :associated_names 
# belongs_to :station, inverse_of: :associated_names 
end 

코드를 실행 중입니다.

(210)
s = Station.first 
s.associated_names.delete_all ==> error 
s.associated_name_ids = [1,3] ==> error 

은 내가 destroy_all DELETE_ALL를 해결하는 것을 알고,하지만 난 솔루션을

감사 업데이트 찾고!

https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-frc3/1011655_10201722818174648_1924981889_n.jpg

답변

0

문제는 협회에 : 여기

문제가있는 코드의 이미지입니다. "delete"작업은 외래 키를 null 기본값으로 설정하고 레코드를 삭제하지 않습니다.

class Station 
    has_many :associated_names, :inverse_of => :station, :dependent => :destroy 
end 

을 다시 코드를 실행합니다 : 그것은에 따라 추가 옵션을

s = Station.first 
s.associated_names.delete_all 
+0

감사합니다! 이게 내 문제를 해결해. – 24sharon

관련 문제