# Different between belongs to and has one?

**URL:** <https://discourse.cakephp.org/t/different-between-belongs-to-and-has-one/3234>\
**Category:** Need Help\
**Created:** [September 19, 2017, 9:06am UTC](https://discourse.cakephp.org/t/different-between-belongs-to-and-has-one/3234 "2017-09-19T09:06:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghori](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@ghori](https://discourse.cakephp.org/u/ghori)\
**Post date:** [September 19, 2017, 9:06am UTC](https://discourse.cakephp.org/t/different-between-belongs-to-and-has-one/3234/1 "2017-09-19T09:06:24Z")

</div>

![image](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex029/uploads/cakephp/original/1X/d4b7cd1082c2d024ad493beb525956ed5f43695c.jpg)diffrent

---

<div class="post-metadata">

**Author:** ![mesiarm](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mesiarm](https://discourse.cakephp.org/u/mesiarm)\
**Post date:** [September 19, 2017, 9:34am UTC](https://discourse.cakephp.org/t/different-between-belongs-to-and-has-one/3234/2 "2017-09-19T09:34:58Z")

</div>

> <https://stackoverflow.com/questions/37582848/what-is-the-difference-between-belongsto-and-hasone-in-laravel>

---

<div class="post-metadata">

**Author:** ![ghori](https://avatars.discourse-cdn.com/v4/letter/g/a183cd/32.png) [@ghori](https://discourse.cakephp.org/u/ghori)\
**Post date:** [September 19, 2017, 10:06am UTC](https://discourse.cakephp.org/t/different-between-belongs-to-and-has-one/3234/3 "2017-09-19T10:06:55Z")

</div>

i don’t know what difference

---

<div class="post-metadata">

**Author:** ![Diego](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/diego/32/296_2.png) [@Diego](https://discourse.cakephp.org/u/Diego)\
**Post date:** [September 19, 2017, 10:45am UTC](https://discourse.cakephp.org/t/different-between-belongs-to-and-has-one/3234/4 "2017-09-19T10:45:24Z")

</div>

Its just the way you read, using yor image as example:

**User** (id - primary key) =\> **hasOne** =\> **Profile** (user\_id - foreing key)  
this way the developer and the application know that when you are at a USER context and need to look for this user PROFILE information you should search in the profiles table by the user foreing key (user\_id)

**Profile** (user\_id - foreing key) =\> **BelongsTo** =\> **User** (id - primary key)  
in this other way when you are at a profile context and need know whats the associated user of this profile you should search the user’s primary key (id) in USERS table

all this information are used to compose the sql joins

![](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex029/uploads/cakephp/original/1X/cd69ede95f99ddff8466d7bfd1bb39956efe9631.jpg)
