If you want to set up a one-to-one relationship between two models, you'll need to add belongs_to to one, and has_one to the other. How do you know which is which?



If you want to set up a one-to-one relationship between two models, you'll need to add belongs_..

Answer / Nikul Singh

In a one-to-one relationship, `belongs_to` is used on the dependent model (the one that 'belongs to' another model). Conversely, `has_one` is used on the parent model (the one that 'has one' dependent model).

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Ruby on Rails Interview Questions

what are some advantages of using ruby on rails?

1 Answers  


Is it possible to build a 50% bespoke e-commerce platform hence having the ability to customize everything down the line? For example would it make sense to start coding an application on the Ruby on Rails framework but where the most complex/time consuming code pieces (e.g. shopping cart, etc) can be initially bolted on (hence diminishing development time and cost) having the ability to change them completely further down the line?

1 Answers  


Mention the log that has to be seen to report errors in Ruby Rails?

1 Answers  


What are gemsets in rails?

1 Answers  


Tell me what is mixin in rails?

1 Answers  


Explain about restful architecture?

1 Answers  


What is the use of super in Ruby Rails?

1 Answers  


Write the command to update rvm in rails.

1 Answers  


What is the rail console?

1 Answers  


Explain dry in rails?

1 Answers  


Do you know the role of garbage collection in ruby on rails?

1 Answers  


What is the difference between symbol and string?

1 Answers  


Categories