-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.rb
67 lines (60 loc) · 1.32 KB
/
demo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require_relative 'record_conjurer.rb'
DBConnection.reset # this will delete and or create the sample db.
class Album < RecordConjurer
belongs_to :artist,
primary_key: :id,
foreign_key: :ArtistId
has_many :tracks,
primary_key: :id,
foreign_key: :AlbumId
finalize!
end
class Artist < RecordConjurer
has_many :albums,
primary_key: :id,
foreign_key: :ArtistId
finalize!
end
class Genre < RecordConjurer
has_many :tracks,
primary_key: :id,
foreign_key: :GenreId
finalize!
end
class MediaType < RecordConjurer
has_many :tracks,
primary_key: :id,
foreign_key: :MediaTypeId
finalize!
end
class Playlists < RecordConjurer
has_many :playlist_tracks,
primary_key: :id,
foreign_key: :PlaylistId
finalize!
end
class PlaylistTrack < RecordConjurer
belongs_to :playlist,
primary_key: :id,
foreign_key: :PlaylistId
belongs_to :track,
primary_key: :id,
foreign_key: :TrackId
finalize!
end
class Track < RecordConjurer
belongs_to :album,
primary_key: :id,
foreign_key: :AlbumId
has_one_through :artist, :album, :artist
belongs_to :genre,
primary_key: :id,
foreign_key: :GenreId
belongs_to :media_type,
primary_key: :id,
foreign_key: :MediaTypeId
has_many :playlist_tracks,
primary_key: :id,
foreign_key: :TrackId
finalize!
end