Hi, I’ve got a problem with two models, connected via belongs_to and
has_many associations. Lets say they are Article, and Category. In the
Article the key is article_id and foreign key column is category_id, in
the Category is key category_id (so keys are not just id). How can I
solve this (categories.id does not exist Fparse_func.c L1036
Runknown_attribute: SELECT * FROM categories WHERE (categories.id = 1)
LIMIT 1)? I need to specify that the key in category is not id but
category_id…
Hi, I’ve got a problem with two models, connected via belongs_to and
has_many associations. Lets say they are Article, and Category. In the
Article the key is article_id and foreign key column is category_id, in
the Category is key category_id (so keys are not just id). How can I
solve this (categories.id does not exist Fparse_func.c L1036
Runknown_attribute: SELECT * FROM categories WHERE (categories.id = 1)
LIMIT 1)? I need to specify that the key in category is not id but
category_id…
class Article < ActiveRecord::Base
set_primary_key “article_id”
belongs_to :category, :foreign_key => “category_id”
end