Skip to content

Commit

Permalink
Fix many to many relation naming
Browse files Browse the repository at this point in the history
* Rename resource_quota_users to resource_quotas_users
* Rename resource_quota_usergroups to resource_quotas_usergroups
  • Loading branch information
bastian-src committed Apr 23, 2024
1 parent b7be50d commit 4c9e646
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/models/concerns/foreman_resource_quota/user_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module ForemanResourceQuota
module UserExtensions
extend ActiveSupport::Concern
included do
has_many :resource_quota_users, class_name: 'ForemanResourceQuota::ResourceQuotaUser', dependent: :destroy,
has_many :resource_quotas_users, class_name: 'ForemanResourceQuota::ResourceQuotaUser', dependent: :destroy,
inverse_of: :user
has_many :resource_quotas, class_name: 'ForemanResourceQuota::ResourceQuota', through: :resource_quota_users
has_many :resource_quotas, class_name: 'ForemanResourceQuota::ResourceQuota', through: :resource_quotas_users
attribute :resource_quota_is_optional, :boolean, default: false

scoped_search relation: :resource_quotas, on: :name, complete_value: true, rename: :resource_quota
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module ForemanResourceQuota
module UsergroupExtensions
extend ActiveSupport::Concern
included do
has_many :resource_quota_usergroups, class_name: 'ForemanResourceQuota::ResourceQuotaUsergroup',
has_many :resource_quotas_usergroups, class_name: 'ForemanResourceQuota::ResourceQuotaUsergroup',
dependent: :destroy, inverse_of: :usergroup
has_many :resource_quotas, class_name: 'ForemanResourceQuota::ResourceQuota', through: :resource_quota_usergroups
has_many :resource_quotas, class_name: 'ForemanResourceQuota::ResourceQuota', through: :resource_quotas_usergroups

scoped_search relation: :resource_quotas, on: :name, complete_value: true, rename: :resource_quota
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/foreman_resource_quota/resource_quota.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class ResourceQuota < ApplicationRecord

self.table_name = 'resource_quotas'

has_many :resource_quota_users, class_name: 'ResourceQuotaUser', inverse_of: :resource_quota, dependent: :destroy
has_many :users, class_name: '::User', through: :resource_quota_users
has_many :resource_quota_usergroups, class_name: 'ResourceQuotaUsergroup', inverse_of: :resource_quota,
has_many :resource_quotas_users, class_name: 'ResourceQuotaUser', inverse_of: :resource_quota, dependent: :destroy
has_many :users, class_name: '::User', through: :resource_quotas_users
has_many :resource_quotas_usergroups, class_name: 'ResourceQuotaUsergroup', inverse_of: :resource_quota,
dependent: :destroy
has_many :usergroups, class_name: '::Usergroup', through: :resource_quota_usergroups
has_many :usergroups, class_name: '::Usergroup', through: :resource_quotas_usergroups
has_many :hosts, class_name: '::Host::Managed', dependent: :nullify

validates :name, presence: true, uniqueness: true
Expand Down
4 changes: 2 additions & 2 deletions app/models/foreman_resource_quota/resource_quota_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ForemanResourceQuota
class ResourceQuotaUser < ApplicationRecord
self.table_name = 'resource_quotas_users'

belongs_to :resource_quota, inverse_of: :resource_quota_users
belongs_to :user, class_name: '::User', inverse_of: :resource_quota_users
belongs_to :resource_quota, inverse_of: :resource_quotas_users
belongs_to :user, class_name: '::User', inverse_of: :resource_quotas_users
end
end
4 changes: 2 additions & 2 deletions app/models/foreman_resource_quota/resource_quota_usergroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ForemanResourceQuota
class ResourceQuotaUsergroup < ApplicationRecord
self.table_name = 'resource_quotas_usergroups'

belongs_to :resource_quota, inverse_of: :resource_quota_usergroups
belongs_to :usergroup, class_name: '::Usergroup', inverse_of: :resource_quota_usergroups
belongs_to :resource_quota, inverse_of: :resource_quotas_usergroups
belongs_to :usergroup, class_name: '::Usergroup', inverse_of: :resource_quotas_usergroups
end
end

0 comments on commit 4c9e646

Please sign in to comment.