public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
mephisto / app / models / assigned_asset.rb
100644 15 lines (13 sloc) 0.54 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class AssignedAsset < ActiveRecord::Base
  belongs_to :article, :counter_cache => 'assets_count'
  belongs_to :asset
  acts_as_list :scope => :article_id
  validates_presence_of :article_id, :asset_id
  validate_on_create :check_for_dupe_article_and_asset
 
  protected
    def check_for_dupe_article_and_asset
      unless self.class.count(:all, :conditions => ['article_id = ? and asset_id = ?', article_id, asset_id]).zero?
        errors.add_to_base("Cannot have a duplicate assignment for this article and asset")
      end
    end
end