19
Setting Up Associations
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.
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?
Related posts:
Post comment
Recommended Services
Recent Posts
- Fantastic new corporate themes for WordPress
- Vistaprint offers FREE t-shirts, too!
- 80+ “Your Ad Here” 125 x 125 banners
- 5 Minute Long Tail SEO Drill: More Traffic, Better SERPs
- iPhone and iPod Touch app statistics: OS adoption, purchasing rates
Recent Comments
- Neerav on Using JavaScript to validate one or more grouped checkboxes
- Jacob on Using JavaScript to validate one or more grouped checkboxes
- kaify on Using JavaScript to validate one or more grouped checkboxes
- JC Goldenstein on How To: Cloak your Affiliate Links for Free in Under 3 Seconds
- Bail Bonds Los Angeles on Amazon Web Services on Rails
Categories
- .net
- acoustic guitar
- affiliate marketing
- ajax
- amazon associates
- blogging
- books
- business ideas
- c#
- code igniter
- dealdotcom
- google adsense
- google adwords
- internet marketing
- iPhone
- javascript
- leadership
- make money online
- mortgage goal
- msn adcenter
- networking
- personal development
- php
- ppc
- ruby
- ruby on rails
- seo
- text-link-ads
- web development
- yahoo search marketing


