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
On 12/29/05, Jason Ketterman
<jason.ketterman-YHLYzh9cQ8BjrEqMGRc/AA@public.gmane.org>
wrote:>
> 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
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails