DEV Community

MD: HAFIZUL ISLAM
MD: HAFIZUL ISLAM

Posted on

2 1

Has-One Relation in Rails with Example

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay