Rails: ActiveRecord has_many association not working
rails-activerecord, ruby-on-rails, ruby-on-rails-4
Solution
Add
has_many :user_graphs
to the `User` and `Upload` classes.
The :through option defines a second association on top of this one.
Problem
I'm a bit new to Rails Active Record associations. I've tried to set up a relationship, but I get ActiveRecord error when I try to retrieve data. Did I associate my models incorrectly? User has many Uploads, which has many UserGraphs: ``` class User < ActiveRecord::Base has_many :uploads, through: :user_graphs end class Upload < ActiveRecord::Base has_many :users, through: :user_graphs end class UserGraph < ActiveRecord::Base belongs_to :user belongs_to :upload end ``` I want to get all of a user's uploads, and all of a user's graphs. The 2nd line doesn't work in rails console and gives an error ``` @user = User.find(1) @uploads = @user.uploads ``` The error: ``` ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :user_graphs in model User ``` Extra Credit: If Users have Uploads that have UserGraphs... shouldn't it be `has_many :uploads` and `has_many :user_graphs, through :uploads`?