# Building Relationship between Models

**URL:** <https://www.ruby-forum.com/t/building-relationship-between-models/163049>\
**Category:** Rails\
**Created:** [March 16, 2009, 11:44pm UTC](https://www.ruby-forum.com/t/building-relationship-between-models/163049 "2009-03-16T23:44:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ialuronico](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@ialuronico](https://www.ruby-forum.com/u/ialuronico)\
**Post date:** [March 16, 2009, 11:44pm UTC](https://www.ruby-forum.com/t/building-relationship-between-models/163049/1 "2009-03-16T23:44:25Z")

</div>

Hi again… 🙂

I’m still working on RoR

right now i’m fighting against relationship.

I generated 3 scaffolds  
car  
wheel  
engine

all the 3 CRUD works and now in the database I’ve many engines , many  
wheel and many cars.

I want to correlate this object but how do it ?

I must say that car has\_one engine and engine belongs\_to car  
(every car can have only one engine)

or i must write that engine has\_many cars and car belongs\_to engine  
(one engine is used on many different car)

or I need to create a new scaffold like road\_ready\_car which has\_one  
engine , has\_one car and has\_many wheels

???

---

<div class="post-metadata">

**Author:** ![ialuronico](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@ialuronico](https://www.ruby-forum.com/u/ialuronico)\
**Post date:** [March 17, 2009, 9:51am UTC](https://www.ruby-forum.com/t/building-relationship-between-models/163049/2 "2009-03-17T09:51:12Z")

</div>

2009/3/16 Simone R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> I generated 3 scaffolds
> 
> I must say that car has\_one engine and engine belongs\_to car  
> (every car can have only one engine)
> 
> or i must write that engine has\_many cars and car belongs\_to engine  
> (one engine is used on many different car)
> 
> or I need to create a new scaffold like road\_ready\_car which has\_one  
> engine , has\_one car and has\_many wheels

It all depends what you want in the database. Are the cars in the  
database  
individual cars, or types of car? If types of car then maybe the name  
is  
wrong. Similarly are the engines actual engines or just types of  
engines?  
The same for wheels.

If they are all actual individual items then a car has only one engine  
and  
an engine has only one car (at any one time at least). A car has 4  
wheels (5  
including spare?) so car has many wheels, wheel belongs to car.

If, however you are talking about types of cars and engines then a car  
type  
may have many engine types and an engine type may have many car types.  
Perhaps in this case you then need another table for the actual cars  
where a  
car is of one car type, one engine type and one wheel type.

---

<div class="post-metadata">

**Author:** ![ialuronico](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@ialuronico](https://www.ruby-forum.com/u/ialuronico)\
**Post date:** [March 17, 2009, 10:53am UTC](https://www.ruby-forum.com/t/building-relationship-between-models/163049/3 "2009-03-17T10:53:48Z")

</div>

Colin L. wrote:

> It all depends what you want in the database.  
> Are the cars in the database  
> individual cars, or types of car?

Thanks for the good hint …

Now I know I was thinking about types of cars 🙂  
(something like a web configurator for a cars webstore)

Now I will try to make it
