HABTM Dependency Question


#1

I have a habtm relationship like the following:

Automobile <–> Options

What I want to do is when an option is deleted, make sure that there
are no Automobiles that still have that option. It seems simple
enough, but I am having a tough time with it. I believe Rails
automagically deletes the relationships when the automobile is
deleted, but not the other way around.

Any help would be appreciated!

Thanks,
Jason


#2

auto1 = Automobile.create(…)
auto2 = Automobile.create(…)
cdplayer = Option.create(…)

add the cdplayer to both autos

auto1.options << cdplayer
auto2.options << cdplayer

show options

auto1.options
auto2.options

doing this will delete the cdplayer option and also remove any

cdplayer
relationships

since cdplayer no longer exists in the database

cdplayer.destroy

doing this will delete the auto1 automobile and also remove any auto1

relationships

since auto1 no longer exists in the database

auto1.destroy