# Which relationship to use?

**URL:** <https://www.ruby-forum.com/t/which-relationship-to-use/140182>\
**Category:** Rails\
**Created:** [June 11, 2008, 5:24pm UTC](https://www.ruby-forum.com/t/which-relationship-to-use/140182 "2008-06-11T17:24:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davi\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@Davi\_V](https://www.ruby-forum.com/u/Davi_V)\
**Post date:** [June 11, 2008, 5:24pm UTC](https://www.ruby-forum.com/t/which-relationship-to-use/140182/1 "2008-06-11T17:24:25Z")

</div>

Hi all.

I’ve the following scenario:

users  
id

cars  
id  
name

One user has many cars, but I need to always edit cars table (add more  
models, edit actual models, etc.). So, I’m think about use another  
table:

cars\_users  
id\_user  
id\_car

This means an HABTM relationship, right? Is this the rigth approach to  
my  
problem? One user doesn’t belongs to a car (in my point of view).

What should I do?

## Best regards and sorry my poor English,

## Davi V.

E-mail: removed\_email\_address@domain.invalid  
MSN : removed\_email\_address@domain.invalid  
GTalk : removed\_email\_address@domain.invalid  
Skype : davi vidal  
YIM : davi\_vidal  
ICQ : 138815296

---

<div class="post-metadata">

**Author:** ![Davi\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@Davi\_V](https://www.ruby-forum.com/u/Davi_V)\
**Post date:** [June 11, 2008, 5:35pm UTC](https://www.ruby-forum.com/t/which-relationship-to-use/140182/2 "2008-06-11T17:35:35Z")

</div>

hey Davi.

You might want to look into “has\_many :through =\>” and use a join  
table for the relationship.

best.  
mike

---

<div class="post-metadata">

**Author:** ![Davi\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@Davi\_V](https://www.ruby-forum.com/u/Davi_V)\
**Post date:** [June 11, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/which-relationship-to-use/140182/3 "2008-06-11T17:37:23Z")

</div>

> cars\_users  
> id\_user  
> id\_car
> 
> ```
> This means an HABTM relationship, right? Is this the rigth approach to my
> 
> ```
> 
> problem? One user doesn’t belongs to a car (in my point of view).

Yes, your secong version would be a habtm. But what for?  
If one user can have several cars, but a car only belongs to a single  
user there is no need for that.  
(This has nothing to do with editing)

The simple question:  
Can a car have several users?  
If yes, you’ll need habtm, otherwise it’s not necessary.
