2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-10-13 16:55:03 +01:00
|
|
|
class ProjectToRepository < ActiveRecord::Base
|
|
|
|
belongs_to :project
|
|
|
|
belongs_to :repository
|
2011-10-28 12:16:32 +01:00
|
|
|
|
|
|
|
delegate :path, :to => :project
|
2011-10-19 14:14:53 +01:00
|
|
|
|
2012-12-18 17:29:21 +00:00
|
|
|
after_destroy lambda { project.destroy_project_from_repository(repository) }, :unless => lambda {Thread.current[:skip]}
|
2011-12-23 17:06:47 +00:00
|
|
|
|
|
|
|
validate :one_project_in_platform_repositories
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def one_project_in_platform_repositories
|
2012-01-28 01:04:11 +00:00
|
|
|
errors.add(:project, 'should be one in platform') if Project.joins(:repositories => :platform).
|
|
|
|
where('platforms.id = ?', repository.platform_id).by_name(project.name).count > 0
|
2011-12-23 17:06:47 +00:00
|
|
|
end
|
2011-10-13 16:55:03 +01:00
|
|
|
end
|