In Rails, Two Active Record models are connected by an association. Why do we need associations between models? Because associations make joint operations easier in our code. For example, we consider two models for Employe and a model for Account. Each Employe can have only one Account. so we discuss has-one-relations or has-one-associations in rails by Employe and Book model.
A has-one-association indicates that one row has one instance of another model called one-to-one or has-one relation or association. That model can be fetched through this association.
For example, if each employee in your application has only one account, First we create two models Employe and Account to describe a has-one-association or has-one-relation or one-to-one relations in Rails.
https://www.cstutorial.org/ruby-on-rails/has-one-relation-in-rails-with-example
Top comments (0)