Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix many to many relation naming #43

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading