# Asymmetrical HABTM(?)

**URL:** <https://discuss.rubyonrails.org/t/asymmetrical-habtm/32125>\
**Category:** rubyonrails-talk\
**Created:** [July 21, 2008, 4:25am UTC](https://discuss.rubyonrails.org/t/asymmetrical-habtm/32125 "2008-07-21T04:25:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stan\_Baptista](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@Stan\_Baptista](https://discuss.rubyonrails.org/u/Stan_Baptista)\
**Post date:** [July 21, 2008, 4:25am UTC](https://discuss.rubyonrails.org/t/asymmetrical-habtm/32125/1 "2008-07-21T04:25:33Z")

</div>

What is the best way to set up a relationship between two tables where table-1 has a one-to-one relationship with table-2 but table-2 has a one-to-many relationship with table-1?

For example, suppose there is an events application (seminars, forums, conferences, etc). Each event has only one address but since many events can occur at the same location throughout the year, a given address can belong to many events.

Thanks, Stan

---

<div class="post-metadata">

**Author:** ![rab](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/rab/32/710_2.png) [@rab](https://discuss.rubyonrails.org/u/rab)\
**Post date:** [July 21, 2008, 4:42am UTC](https://discuss.rubyonrails.org/t/asymmetrical-habtm/32125/2 "2008-07-21T04:42:09Z")

</div>

That's just a normal association:

class Event \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;belongs\_to :address end

class Address \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;has\_many :events end

Don't let the seemingly backward "belongs\_to :address" fool you. The 'belongs\_to' association is on the model that contains the foreign key (address\_id in this example) even though you say "Each event has only one address..." -- the "has ... one" is misleading in this case.

-Rob

Rob Biedenharn [http://agileconsultingllc.com](http://agileconsultingllc.com) Rob@AgileConsultingLLC.com

---

<div class="post-metadata">

**Author:** ![Stan\_Baptista](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@Stan\_Baptista](https://discuss.rubyonrails.org/u/Stan_Baptista)\
**Post date:** [July 21, 2008, 4:56am UTC](https://discuss.rubyonrails.org/t/asymmetrical-habtm/32125/3 "2008-07-21T04:56:17Z")

</div>

> Don't let the seemingly backward "belongs\_to :address" fool you. The 'belongs\_to' association is on the model that contains the foreign key (address\_id in this example) even though you say "Each event has only one address..." -- the "has ... one" is misleading in this case.

Got it. Thanks Rob.

---

<div class="post-metadata">

**Author:** ![Pardee\_Roy](https://avatars.discourse-cdn.com/v4/letter/p/f0a364/32.png) [@Pardee\_Roy](https://discuss.rubyonrails.org/u/Pardee_Roy)\
**Post date:** [July 21, 2008, 3:15pm UTC](https://discuss.rubyonrails.org/t/asymmetrical-habtm/32125/4 "2008-07-21T15:15:21Z")

</div>

That sounds like a plain 1:many to me. Address has\_many :events, and Event belongs\_to :address.
