I would like to have as a model
Dogs
has_one :cat
and have a cat_id in the dog table… then I would like to call Dog.first.cat
This doesn’t seem to be working for me. Am I missing something
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re using
has_one, so it’s actually thecatstable that should have thedog_id.In your case, you would use
belongs_to :catin theDogmodel.Take a look at the doc: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#label-Is+it+a+belongs_to+or+has_one+association%3F