title: Rails Complex Database Relationships
body: <p>I am working on a project which consists of Schools, Students and Articles. As I started developing my Articles controller I realized that there had to be a better way to accomplish my goal, but I just don't have the experience to figure it out. Basically what I am trying to do is have my Users register to a certain school. Then once the user logs in, he should be able to see all articles from his school and by category. Here is my setup, any advice would be appreciated:</p>
  
  <p>school.rb:</p>
  
  <pre><code>class School &lt; ActiveRecord::Base
    has_many :users
    has_many :articles, :through =&gt; :users
    attr_accessible :name
  end
  </code></pre>
  
  <p>user.rb:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    belongs_to :school
    has_many :articles
    attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :remember_me, :provider, :uid, :school_id
  end
  </code></pre>
  
  <p>category.rb:</p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
    attr_accessible :name
    has_many :articles
    accepts_nested_attributes_for :articles
  end
  </code></pre>
  
  <p>article.rb:</p>
  
  <pre><code>class Article &lt; ActiveRecord::Base
    attr_accessible :body
    belongs_to :category
    belongs_to :user
  end
  </code></pre>
  
  <p>Does this seem like a good setup to accomplish my goal? Thanks in advanced.</p>