Forum: Ruby on Rails ActiveRecord and cascade removing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
zven (Guest)
on 2006-05-13 22:40
(Received via mailing list)
Hi. Please help me how to make cascade delete for this 3 classes:

class Section < ActiveRecord:Base
  has_many :ad_bindings
  has_many: banners, :through => :ad_bindings
end

class AdBinding < ActiveRecord:Base
  belongs_to :banner
end

class Banner < ActiveRecord:Base

end

When I remove Banner, I need to remove AdBinding also, but it still
stored in database. Where I wrong?
Kenneth L. (Guest)
on 2006-05-13 23:04
(Received via mailing list)
Try

belongs_to :banner, :dependent => true

This says that the child row cannot exist without the row in the parent
table, and will do a cascading delete.

Ken
zven (Guest)
on 2006-05-13 23:20
(Received via mailing list)
On Sat, 2006-05-13 at 21:03 +0200, Kenneth L. wrote:
> Try
>
> belongs_to :banner, :dependent => true
>
> This says that the child row cannot exist without the row in the parent
> table, and will do a cascading delete.
>
> Ken
>

It's not helpful, I still have rows in 'ad_bindings' table (
zven (Guest)
on 2006-05-13 23:44
(Received via mailing list)
Ok. I got:

class Banner...
  has_many :ad_bindings, :dependent => :destroy
end
This topic is locked and can not be replied to.