diff --git a/app/models/artist.rb b/app/models/artist.rb index be0affb..d32e556 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -4,13 +4,16 @@ class Artist < ActiveRecord::Base def get_genre_of_first_song #return the genre of the artist's first saved song + self.songs.first.genre end def song_count #return the number of songs associated with the artist + self.songs.count end def genre_count #return the number of genres associated with the artist + self.genres.count end end diff --git a/app/models/genre.rb b/app/models/genre.rb index 9d932e6..e188193 100644 --- a/app/models/genre.rb +++ b/app/models/genre.rb @@ -4,13 +4,16 @@ class Genre < ActiveRecord::Base def song_count # return the number of songs in a genre + self.songs.count end def artist_count # return the number of artists associated with the genre + self.artists.count end def all_artist_names # return an array of strings containing every musician's name + self.artists.map{|artist| artist.name} end end diff --git a/app/models/song.rb b/app/models/song.rb index e9317af..15aed03 100644 --- a/app/models/song.rb +++ b/app/models/song.rb @@ -3,9 +3,12 @@ class Song < ActiveRecord::Base belongs_to :genre def get_genre_name + self.genre.name end def drake_made_this # when this method is called it should assign the song's artist to Drake + self.artist = Artist.new({"name" => "Drake"}) end -end \ No newline at end of file + +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..43856f3 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,30 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 5) do + + create_table "artists", force: :cascade do |t| + t.string "name" + end + + create_table "genres", force: :cascade do |t| + t.string "name" + end + + create_table "songs", force: :cascade do |t| + t.string "name" + t.integer "artist_id" + t.integer "genre_id" + end + +end