rails associations - How would you represent this relationship?

Posted by truthSeekr on Stack Overflow See other posts from Stack Overflow or by truthSeekr
Published on 2011-03-06T08:06:10Z Indexed on 2011/03/06 8:10 UTC
Read the original article Hit count: 500

Hello All,

I am trying to figure out a best way to represent the following relationship.

Newspaper-->has_many-->Articles
Newspaper-->has_many--->Subscribers

Subscribers are allowed to save the articles for their personal page.

 Two Questions:

1) How would the relationship look like in rails?    
  How would the action 'save' look like?

 The following using has_many does not seem right to me:

  ArticleController < ApplicationController
  def save
   a = Article.find(101)
   @user.saved_articles << a
  end

2) Do I need a join table Saved_Articles that looked like this?

Saved_Articles
----------------
user_id, article_id

I am not sure how the has_many_through works. any advice is appreciated.

thanks

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord