2013-05-06 05:26:36 -04:00
|
|
|
class DeployKeysProject < ActiveRecord::Base
|
|
|
|
belongs_to :project
|
|
|
|
belongs_to :deploy_key
|
|
|
|
|
|
|
|
validates :deploy_key_id, presence: true
|
|
|
|
validates :deploy_key_id, uniqueness: { scope: [:project_id], message: "already exists in project" }
|
|
|
|
validates :project_id, presence: true
|
2015-03-17 09:55:43 -04:00
|
|
|
|
|
|
|
after_destroy :destroy_orphaned_deploy_key
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def destroy_orphaned_deploy_key
|
2015-04-03 06:22:44 -04:00
|
|
|
return unless self.deploy_key.destroyed_when_orphaned? && self.deploy_key.orphaned?
|
|
|
|
|
2015-03-27 09:43:48 -04:00
|
|
|
self.deploy_key.destroy
|
2015-03-17 09:55:43 -04:00
|
|
|
end
|
2013-05-06 05:26:36 -04:00
|
|
|
end
|