Skip to content

Instantly share code, notes, and snippets.

@amrnt
Created April 15, 2010 18:15
Show Gist options
  • Save amrnt/367446 to your computer and use it in GitHub Desktop.
Save amrnt/367446 to your computer and use it in GitHub Desktop.
songs = Song.find_by_sql("SELECT * FROM songs GROUP BY genre")
songs.each{ |song| Genre.create!(:name => song.genre) } # Genre jahez
songs.each do |song|
genre = Genre.find_by_name(song.genre)
Music.create!(:genre_id => genre.id, :song_name => song.name) #Music table jahez related with Genre
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment