public
Description: A Web-2.0 style, AJAX powered lyrics database using Ruby on Rails
Homepage: http://shanesveller.com/projects/
Clone URL: git://github.com/shanesveller/rails-lyrics.git
Album model fixes
shanesveller (author)
Thu Jul 17 07:32:22 -0700 2008
commit  f79f4d0ce5346c003d3999d48badac1e6cb5c677
tree    f0acd7f65844a89b796310584abd5997b660478d
parent  0ab35c871d3db61e2896fd56f28d4c6fd4c15314
...
1
 
 
2
...
1
2
3
4
0
@@ -1,2 +1,4 @@
0
 class Album < ActiveRecord::Base
0
+ belongs_to :artist
0
+ has_many :lyrics
0
 end
...
1
 
2
3
...
1
2
3
4
0
@@ -1,3 +1,4 @@
0
 class Artist < ActiveRecord::Base
0
+ has_many :albums
0
   has_many :lyrics
0
 end
...
3
4
5
6
 
 
7
8
9
10
 
11
12
13
...
3
4
5
 
6
7
8
9
10
11
12
13
14
15
0
@@ -3,11 +3,13 @@ require 'open-uri'
0
 
0
 class Lyric < ActiveRecord::Base
0
   is_indexed :fields => ['album','title','body'],
0
- :include => [{:association_name => 'artist', :field => 'name', :as => 'artist_name'}]
0
+ :include => [{:association_name => 'artist', :field => 'name', :as => 'artist_name'},
0
+ {:association_name => 'album', :field => 'title', :as => 'album_title'}]
0
   
0
   named_scope :blank, :conditions => { :body => nil }
0
   
0
   belongs_to :artist
0
+ belongs_to :album
0
   
0
   def scrape_plyrics
0
     song = self
...
1
2
 
3
4
5
...
36
37
38
39
 
40
41
42
...
1
 
2
3
4
5
...
36
37
38
 
39
40
41
42
0
@@ -1,5 +1,5 @@
0
 
0
-# Auto-generated at Mon Jul 14 15:27:56 -0400 2008.
0
+# Auto-generated at Thu Jul 17 10:26:45 -0400 2008.
0
 # Hand modifications will be overwritten.
0
 # /Users/shane/rails/lyl/config/ultrasphinx/default.base
0
 indexer {
0
@@ -36,7 +36,7 @@ sql_pass =
0
 sql_sock = /opt/local/var/run/mysql5/mysqld.sock
0
 sql_user = root
0
 sql_query_range = SELECT MIN(id) , MAX(id) FROM lyrics
0
-sql_query = SELECT (lyrics.id * 1 + 0) AS id, lyrics.album AS album, artist.name AS artist_name, lyrics.body AS body, 'Lyric' AS class, 0 AS class_id, lyrics.title AS title FROM lyrics LEFT OUTER JOIN artists AS artist ON artist.id = lyrics.artist_id WHERE lyrics.id >= $start AND lyrics.id <= $end GROUP BY lyrics.id
0
+sql_query = SELECT (lyrics.id * 1 + 0) AS id, lyrics.album AS album, album.title AS album_title, artist.name AS artist_name, lyrics.body AS body, 'Lyric' AS class, 0 AS class_id, lyrics.title AS title FROM lyrics LEFT OUTER JOIN artists AS artist ON artist.id = lyrics.artist_id LEFT OUTER JOIN albums AS album ON album.id = lyrics.album_id WHERE lyrics.id >= $start AND lyrics.id <= $end GROUP BY lyrics.id
0
 
0
 sql_attr_uint = class_id
0
 sql_query_info = SELECT * FROM lyrics WHERE lyrics.id = (($id - 0) / 1)
...
2
3
4
5
6
7
8
...
2
3
4
 
5
6
7
0
@@ -2,7 +2,6 @@ class CreateLyrics < ActiveRecord::Migration
0
   def self.up
0
     create_table :lyrics, :force => true do |t|
0
       t.column :title, :string
0
- t.column :album, :string
0
       t.column :year, :integer
0
       t.column :track, :integer
0
       t.column :genre, :string
...
7
8
9
 
 
 
10
11
12
13
 
14
15
...
7
8
9
10
11
12
13
14
15
16
17
18
19
0
@@ -7,9 +7,13 @@ class CreateArtists < ActiveRecord::Migration
0
       t.column :label, :string
0
       t.column :members, :text
0
     end
0
+
0
+ add_column :lyrics, :artist_id, :integer
0
+
0
   end
0
 
0
   def self.down
0
     drop_table :artists
0
+ remove_column :table_name, :column_name
0
   end
0
 end
...
5
6
7
 
 
 
8
9
10
 
11
12
13
...
5
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -5,9 +5,13 @@ class CreateAlbums < ActiveRecord::Migration
0
       t.column :year, :integer
0
       t.column :artist_id, :integer
0
     end
0
+
0
+ add_column :lyrics, :album_id, :integer
0
+
0
   end
0
 
0
   def self.down
0
+ remove_column :lyrics, :album_id
0
     drop_table :albums
0
   end
0
 end
...
33
34
35
 
36
37
38
...
33
34
35
36
37
38
39
0
@@ -33,6 +33,7 @@ ActiveRecord::Schema.define(:version => 20080715193737) do
0
     t.string "genre"
0
     t.text "body"
0
     t.integer "artist_id", :limit => 11
0
+ t.integer "album_id", :limit => 11
0
   end
0
 
0
   create_table "users", :force => true do |t|
...
38
39
40
 
 
 
 
 
 
 
41
42
 
43
44
45
46
47
 
48
49
50
...
38
39
40
41
42
43
44
45
46
47
48
 
49
50
51
52
53
54
55
56
57
58
0
@@ -38,13 +38,21 @@ namespace :import do
0
         art.genre ||= genre
0
         puts "New artist: #{artist}" if art.id.nil?
0
         art.save
0
+
0
+ if !album.blank? && !album.nil?
0
+ alb = Album.find_or_initialize_by_title_and_artist_id(album, art.id)
0
+ alb.year ||= year
0
+ puts "New album: #{album} by #{artist}" if alb.id.nil?
0
+ alb.save
0
+ end
0
 
0
- song = Lyric.find_or_initialize_by_title_and_artist_id_and_album(title,art.id,album)
0
+ song = Lyric.find_or_initialize_by_title_and_artist_id_and_album_id(title,art.id,alb.id || '')
0
         song.year = year
0
         song.genre = genre
0
         song.track = track
0
         puts "New song: #{title} by #{artist}" if song.id.nil?
0
         art.lyrics << song
0
+ alb.lyrics << song if alb
0
         song.save
0
 
0
       end

Comments

    No one has commented yet.