Skip to content

Instantly share code, notes, and snippets.

@Xorlev
Created December 10, 2011 09:08
Show Gist options
  • Save Xorlev/1454856 to your computer and use it in GitHub Desktop.
Save Xorlev/1454856 to your computer and use it in GitHub Desktop.
AR Models
require 'active_record'
class Album < ActiveRecord::Base
belongs_to :artist
has_many :tracks
has_and_belongs_to_many :genres
attr_accessible :id, :artist_id, :genres
def to_s
"Album(#{id}), Artist(#{artist_id})"
end
end
class Genre < ActiveRecord::Base
has_and_belongs_to_many :albums
has_and_belongs_to_many :tracks
attr_accessible :id
def to_s
"Genre(#{id}) #{name}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment