Created
December 10, 2011 09:08
-
-
Save Xorlev/1454856 to your computer and use it in GitHub Desktop.
AR Models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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