Skip to content

Instantly share code, notes, and snippets.

@xta
Forked from aviflombaum/seed.rake
Created November 2, 2012 20:14
Show Gist options
  • Save xta/4004045 to your computer and use it in GitHub Desktop.
Save xta/4004045 to your computer and use it in GitHub Desktop.
Rails Lab: Associations - seed.rake file for Songs & Artists
desc "Create a bunch of seed data for artists and songs"
task :seed_artists_and_songs => [:environment, :clear_artists_and_songs] do
# Build Song Off Artist
# Given a Song called R.E.S.P.E.C.T
# build the Aretha Franklin Artist
s = Song.create(:name => "R.E.S.P.E.C.T")
s.build_artist(:name => "Aretha Franklin")
s.save
# Build a Song for that Artist
# build song Natural Woman
# Manually Create Artist Kanye West
# Push a Song Onto an Artist
# push a song onto Kanye West
# Create Michael Jackson Artist
# Make 3 Michael Jackson Songs
# push all songs by Michael Jackson
# Delete one michael song off of michael
# Remove a Song from Artist
end
task :clear_artists_and_songs => [:environment] do
puts "Deleting all Artists and Songs...."
Artist.delete_all
Song.delete_all
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment