How to generate a model with has_one contraint

Viewed 4399

I want to create 2 models, where one belongs to another. I know the generate command to create a model that “belongs_to” another but I have no clue how to have the other model have “has_one”.

Can I specify “has_one” in the generate command? Or do I manually add it to the model file after?

This still confuses me since the child that “belongs_to” has the foreign key and the parent that “has_one” doesn’t have anything.

And isn’t this a one-to-one relationship, and so not needed?

1 Answers
Related