The above code is in the super class Taxonomy. This checks to make sure no associations are there for the organization before destroying.
```has_many_hosts :dependent => :nullify``` The above code is in the sub class Organization/Location. This nullifies the host association on the deletion of organization/location object.
We basically need ```has_many_hosts :dependent => :nullify``` to run before ```before_destroy EnsureNotUsedBy.new(:hosts)```
Fixes #15336 - Enables proper deletion of Orgs
Prior to this commit if you had an Org/Location with a host and tried to
the delete the Org. You would end up with an error that looks like
<Org> is used by <Host> (RuntimeError)
Basic error is these 2 areas
https://github.com/theforeman/foreman/blob/develop/app/models/taxonomies/organization.rb#L8
and
https://github.com/theforeman/foreman/blob/develop/app/models/taxonomy.rb#L2
```before_destroy EnsureNotUsedBy.new(:hosts)```
The above code is in the super class Taxonomy. This checks to make sure
no associations are there for the organization before destroying.
```has_many_hosts :dependent => :nullify```
The above code is in the sub class Organization/Location. This nullifies
the host association on the deletion of organization/location object.
We basically need ```has_many_hosts :dependent => :nullify``` to run
before ```before_destroy EnsureNotUsedBy.new(:hosts)```
For the proper ordering of these checks
This commit tries to address that ordering issue