2011-06-14 20:05:12 +04:00
|
|
|
class Album < ActiveRecord::Base
|
2011-06-15 00:01:42 +04:00
|
|
|
belongs_to :artist
|
2011-10-05 15:27:45 +04:00
|
|
|
has_many :tracks, :conditions => ['position > 0'], :order => 'bonus ASC, position ASC', :dependent => :destroy
|
2011-09-26 04:05:46 +04:00
|
|
|
has_many :album_formats
|
|
|
|
has_many :release_formats, :through => :album_formats
|
|
|
|
|
|
|
|
default_scope where(:master => true)
|
2011-11-29 03:22:29 +04:00
|
|
|
after_save :clear_artist_cache
|
2011-09-26 04:05:46 +04:00
|
|
|
|
|
|
|
def self.with_format f
|
|
|
|
joins(:release_formats).where(:release_formats => { :hash => f.to_s })
|
|
|
|
end
|
2011-11-27 16:37:51 +04:00
|
|
|
|
|
|
|
def serialize
|
|
|
|
{
|
|
|
|
name: name,
|
|
|
|
pic_url: pic_url,
|
|
|
|
year: year,
|
|
|
|
tracks: tracks.map(&:serialize)
|
|
|
|
}
|
|
|
|
end
|
2011-11-29 03:22:29 +04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def clear_artist_cache
|
|
|
|
artist.clear_cache
|
|
|
|
end
|
2011-06-14 20:05:12 +04:00
|
|
|
end
|