VN:F [1.9.11_1134]
Rating: 0.0/5 (0 votes cast)

As my first project with RoR, I’m creating a lyrics website. Thus, there are basically three main models that will have to be maintained through the site: artists, albums, and songs.

So, I’m current in the process of setting up associations between the model classes (Artist, Album, Song) so that I can easily access the associated information. I have no idea if what I’m doing currently is correct, but I’ll probably find out tomorrow when I continue working.

NOTE FROM THE AUTHOR, RORY HANSEN
Have you found this post helpful?
If so, I'd appreciate if you could indicate so by pressing the Google Plus button below.

This is what I’ve put into each of the model files so far:

artist.rb
class Artist < ActiveRecord::Base
   has_many :songs, :order => "song_name", :dependent => true
   has_many :albums, :order => "album_name", :dependent => true
end

album.rb
class Album < ActiveRecord::Base
   belongs_to :artist
   has_many :songs, :order => "song_title", :dependent => true
end

song.rb
class Song < ActiveRecord::Base
   belongs_to :artist
   belongs_to :album
end

I have designed the database so that songs do not necessary have to belong to an album, in the case that the album name is not readily available. That's why there's a little bit of redundancy of information.

But, other than that, are any errors apparent to anyone?

VN:F [1.9.11_1134]
Rating: 0.0/5 (0 votes cast)

Related posts:

  1. Ruby on Rails find_by_sql Example
  2. Models with Associations
  3. Implementing Search in Ruby on Rails
  4. Related Drop-down Lists with Ruby on Rails and AJAX
  5. CodeIgniter Blank Page Fix: Blank webpage when setting up CodeIgniter, PHP, MySQL, and Apache

Post comment