2012-08-27 03:53:30 +04:00
|
|
|
class Track < ActiveRecord::Base
|
|
|
|
belongs_to :album
|
|
|
|
has_many :performers
|
|
|
|
has_many :artists, through: :performers
|
|
|
|
|
|
|
|
attr_accessible :album_id, :disc_id, :duration, :position, :rovi_id, :title
|
2012-09-09 17:48:24 +04:00
|
|
|
scope :with_artists, lambda{
|
|
|
|
includes(:artists)
|
|
|
|
}
|
2012-08-27 03:53:30 +04:00
|
|
|
|
|
|
|
def length
|
|
|
|
return if duration.nil?
|
|
|
|
length = duration.divmod(60).map(&:to_s)
|
|
|
|
length[1] = "0" << length[1] if length[1].length == 1
|
|
|
|
length.join(":")
|
|
|
|
end
|
|
|
|
end
|