{"action":"closed","issue":{"url":"https://api.github.com/repos/francesharlow/recipe_wiki/issues/1","labels_url":"https://api.github.com/repos/francesharlow/recipe_wiki/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/francesharlow/recipe_wiki/issues/1/comments","events_url":"https://api.github.com/repos/francesharlow/recipe_wiki/issues/1/events","html_url":"https://github.com/francesharlow/recipe_wiki/issues/1","id":120653309,"number":1,"title":"Setting Up has_many :through Associations","user":{"login":"francesharlow","id":14861882,"avatar_url":"https://avatars.githubusercontent.com/u/14861882?v=3","gravatar_id":"","url":"https://api.github.com/users/francesharlow","html_url":"https://github.com/francesharlow","followers_url":"https://api.github.com/users/francesharlow/followers","following_url":"https://api.github.com/users/francesharlow/following{/other_user}","gists_url":"https://api.github.com/users/francesharlow/gists{/gist_id}","starred_url":"https://api.github.com/users/francesharlow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francesharlow/subscriptions","organizations_url":"https://api.github.com/users/francesharlow/orgs","repos_url":"https://api.github.com/users/francesharlow/repos","events_url":"https://api.github.com/users/francesharlow/events{/privacy}","received_events_url":"https://api.github.com/users/francesharlow/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"annarankin","id":11503403,"avatar_url":"https://avatars.githubusercontent.com/u/11503403?v=3","gravatar_id":"","url":"https://api.github.com/users/annarankin","html_url":"https://github.com/annarankin","followers_url":"https://api.github.com/users/annarankin/followers","following_url":"https://api.github.com/users/annarankin/following{/other_user}","gists_url":"https://api.github.com/users/annarankin/gists{/gist_id}","starred_url":"https://api.github.com/users/annarankin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/annarankin/subscriptions","organizations_url":"https://api.github.com/users/annarankin/orgs","repos_url":"https://api.github.com/users/annarankin/repos","events_url":"https://api.github.com/users/annarankin/events{/privacy}","received_events_url":"https://api.github.com/users/annarankin/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2015-12-06T19:21:06Z","updated_at":"2015-12-06T19:49:48Z","closed_at":"2015-12-06T19:49:48Z","body":"Hi Anna,\r\n\r\nI'm sorry to interrupt your weekend! I hope it's been great thus far.\r\n\r\nIf you have a moment, I'd really appreciate some help setting up the associations between my categories and articles. I've tried a number of different techniques but nothing's worked yet (I'm sorry in advance -- this is going to get long as I try to explain as clearly as possible).\r\n\r\nI'd like to be able to use @category.articles and @article.categories methods in my server, so I can list the categories that apply to an individual article view and, elsewhere on the web application, the articles that belong to an each category. As such, I've set up the following migrations:\r\n\r\n```\r\nclass Article < ActiveRecord::Base\r\n  belongs_to :author, class_name: \"User\"\r\n  has_many :edits, class_name: \"Edit\", foreign_key: \"article_id\"\r\n  has_many :article_categories\r\n  has_many :categories, through: :article_categories\r\n```\r\nand \r\n```\r\nclass Category < ActiveRecord::Base\r\n  has_many :article_categories\r\n  has_many :articles, through: :article_categories\r\nend\r\n```\r\nso that \r\n```\r\nclass ArticleCategory < ActiveRecord::Base\r\n  belongs_to :articles\r\n  belongs_to :categories\r\nend\r\n```\r\nMy schema runs properly, as written:\r\n```\r\nCREATE TABLE articles (\r\n  id INTEGER PRIMARY KEY,\r\n  title VARCHAR,\r\n  ingredients TEXT,\r\n  directions TEXT,\r\n  img_url TEXT,\r\n  created_on DATETIME,\r\n  author_id INTEGER\r\n);\r\n\r\nCREATE TABLE categories (\r\n  id INTEGER PRIMARY KEY,\r\n  name VARCHAR\r\n);\r\n\r\nCREATE TABLE article_categories (\r\n  article_id INTEGER,\r\n  category_id INTEGER\r\n);\r\n```\r\n\r\nHowever, when I try to run my db/seeds.rb file\r\n```\r\nc1 = Category.create(name: \"breakfast\")\r\nc2 = Category.create(name: \"vegan\")\r\n\r\nc1.article_categories.push(a1)\r\nc2.article_categories.push(a2)\r\n```\r\nI get an \"Could not find table 'article_categories' (ActiveRecord::StatementInvalid)\" error. I've tried futzing around and switching the variable order (a1 and a2 into c1 and c2, for instance), as well as c1.articles.push(a1) just to see what would happen, but that gave me a \"uninitialized constant Category::Articles (NameError)\" error, unsurprisingly.\r\n\r\nI think I'm pretty close to getting it to work, but I need a little hint. I'd really love to get to MVP functionality before tomorrow morning. In the meantime, I'll get to work on styling :)\r\n\r\nThanks so much!\r\n\r\n"}}