2011-10-13 16:55:03 +01:00
|
|
|
class ProjectToRepository < ActiveRecord::Base
|
|
|
|
belongs_to :project
|
|
|
|
belongs_to :repository
|
2011-10-19 14:14:53 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
delegate :path, to: :project
|
2011-12-23 17:06:47 +00:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
after_destroy lambda { project.destroy_project_from_repository(repository) }, unless: lambda {Thread.current[:skip]}
|
|
|
|
|
|
|
|
validate :one_project_in_platform_repositories, on: :create
|
2011-12-23 17:06:47 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def one_project_in_platform_repositories
|
2014-01-21 04:51:49 +00:00
|
|
|
errors.add(:base, I18n.t('activerecord.errors.project_to_repository.project')) if Project.joins(repositories: :platform).
|
2013-04-08 15:27:50 +01:00
|
|
|
where('platforms.id = ?', repository.platform_id).by_name(project.name).exists?
|
2011-12-23 17:06:47 +00:00
|
|
|
end
|
2011-10-13 16:55:03 +01:00
|
|
|
end
|