rosa-build/app/models/project_to_repository.rb

19 lines
688 B
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
class ProjectToRepository < ActiveRecord::Base
belongs_to :project
belongs_to :repository
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]}
validate :one_project_in_platform_repositories, :on => :create
protected
def one_project_in_platform_repositories
errors.add(:base, I18n.t('activerecord.errors.project_to_repository.project')) if Project.joins(:repositories => :platform).
where('platforms.id = ?', repository.platform_id).by_name(project.name).exists?
end
end