[katello-devel] HABTM and :dependent => :destroy
Lukas Zapletal
lzap at redhat.com
Thu Jun 30 13:22:20 UTC 2011
On 06/30/2011 03:00 PM, Brad Buckingham wrote:
> For User/Role, we have HABTM relationship between those models with a
> join table of roles_users. With that relationship, I've seen that
> deleting a User does not affect the join or Role; however, deleting a
> Role does remove both the Role and the join from roles_users. This
> basically means that the User model needs to perform something like
> user.role.destroy when the User is destroyed; otherwise, the join & role
> remain orphaned. Is this an example of the issue you see?
>
> One of the other benefits of 'has_many :through' is that it supports
> adding additional attributes to the join model. This is something we
> needed for notices; therefore, I converted it to 'has_many :through' a
> while back.
>
> I'm personally not opposed to not using the HABTM (and I'd be happy to
> help with migrating from it, if we decide to do so); however, I am
> curious under what scenarios we might see issues using HABTM.
+1 for replacing HABTM with has_many.
So what is the exit plan here? I guess we need to put this on the backlog.
$ git grep has_and_belongs_to_many
app/models/changeset.rb: has_and_belongs_to_many :products
app/models/kp_environment.rb: has_and_belongs_to_many :priors,
{:class_name => "KPEnvironment", :foreign_key => :envir
app/models/kp_environment.rb: has_and_belongs_to_many :successors,
{:class_name => "KPEnvironment", :foreign_key => "p
app/models/kp_environment.rb: has_and_belongs_to_many :products, {
:uniq=>true }
app/models/organization.rb: has_and_belongs_to_many :users
app/models/permission.rb: has_and_belongs_to_many :verbs
app/models/permission.rb: has_and_belongs_to_many :tags
app/models/product.rb: has_and_belongs_to_many :environments,
{:class_name => "KPEnvironment", :uniq => true}
app/models/product.rb: has_and_belongs_to_many :changesets
app/models/role.rb: has_and_belongs_to_many :users
app/models/system_template.rb: has_and_belongs_to_many :products, :uniq
=> true
app/models/tag.rb: has_and_belongs_to_many :permission
app/models/user.rb: has_and_belongs_to_many :roles
app/models/user.rb: has_and_belongs_to_many :organizations
app/models/verb.rb: has_and_belongs_to_many :permission
--
Later,
Lukas Zapletal | E32E400A
RHN Satellite Engineering
Red Hat Czech s.r.o. Brno
More information about the katello-devel
mailing list