From: "Dmitry V. Sabanin" Date: 2004-09-27T20:02:54+09:00 Subject: [Rails] #has_and_belongs_to_many problem Hi, I'm playing with Rails and I must say that it's really great framework. Web development was never been so easy and pleasure. However, I'm having a lot of small problems in understanding the New Way(TM) of creating stuff for web. I have a problem when I try to extend ACL example that's listed on wiki: http://activerecord.rubyonrails.org/show/AccessControlListExample There's model Role and Permission, Role#has_and_belongs_to_many permissions, and everything works fine. But, when I remove a Permission that belongs to some Role, I still see reference to it in `permissions_roles` table. I've tried following code to delete all permissions from Role's that use them, but it doesn't work also, links to non-existant Permissions are still in `permissions_roles` table: class Permission < ActiveRecord::Base has_and_belongs_to_many :roles def before_destroy Role.find_all.each do |role| role.permissions(true).each do |perm| # I'm comparing id's here because i'm not sure if # ActiveRecord handles #== right if perm.id == read_attribute("id") role.remove_permissions(perm.id) role.save end end end end end P.S. Maybe that's a problem with me being using MySQL, which has no support for foreign keys in stable version? -- sdmitry -=- Dmitry V. Sabanin MuraveyLabs. Spam Here -> postmaster@sco.com