# Missing? has\_and\_belongs\_to\_many with a has\_one relationship----the tool/helper

**URL:** <https://www.ruby-forum.com/t/missing-has-and-belongs-to-many-with-a-has-one-relationship-the-tool-helper/145019>\
**Category:** Rails\
**Created:** [August 5, 2008, 10:15am UTC](https://www.ruby-forum.com/t/missing-has-and-belongs-to-many-with-a-has-one-relationship-the-tool-helper/145019 "2008-08-05T10:15:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shawn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@shawn](https://www.ruby-forum.com/u/shawn)\
**Post date:** [August 5, 2008, 10:15am UTC](https://www.ruby-forum.com/t/missing-has-and-belongs-to-many-with-a-has-one-relationship-the-tool-helper/145019/1 "2008-08-05T10:15:36Z")

</div>

In a dual boot computer the hardware has\_and\_belongs\_to\_many OS’s,  
each os has only 1 set of hardware–how ever this is not has\_many,  
belongs\_to as the OS does not belong to the hardware, it serves only  
as the conduit.

I see no way to express this in rails–its a reverse has\_many,  
belongs\_to, and is really just a semantics difference—but putting  
belongs to where it doesnt belong makes things ugly because you put  
labels on things that dont make sense.

any help? did i just no find the awnser or does this really not exist?

---

<div class="post-metadata">

**Author:** ![shawn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@shawn](https://www.ruby-forum.com/u/shawn)\
**Post date:** [August 5, 2008, 6:01pm UTC](https://www.ruby-forum.com/t/missing-has-and-belongs-to-many-with-a-has-one-relationship-the-tool-helper/145019/2 "2008-08-05T18:01:03Z")

</div>

I’m not sure to understand exactly what you mean, but i’m afraid there  
isn’t other way to express what you described.  
It sound logical to say that a given Os instance could be linked to  
only one set of hardware. And of course a given set of hardware can  
“see” many Os running (sometime in the mean time!!). So it looks like  
a has\_many-belongs\_to association.

But you can imagine a Conduit object that can be used as a join table:

class Harware \< ActiveRecord  
:has\_many :conduits  
:has\_many :os, througt =\> :conduits  
end

class Os \< ActiveRecord  
:has\_one :conduit  
:has\_one :hardware, :througt =\> :conduit  
end

class Conduit \< ActiveRecord  
:belongs\_to :conduit  
:belongs\_to :os  
end

## I’m not sure it works exactly like that, but hope it helps

Mathieu BODIN
