# Bug in multiple map.resources :has\_many?

**URL:** <https://www.ruby-forum.com/t/bug-in-multiple-map-resources-has-many/111979>\
**Category:** Rails\
**Created:** [August 14, 2007, 12:46am UTC](https://www.ruby-forum.com/t/bug-in-multiple-map-resources-has-many/111979 "2007-08-14T00:46:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![linojon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b3f665/32.png) [@linojon](https://www.ruby-forum.com/u/linojon)\
**Post date:** [August 14, 2007, 12:46am UTC](https://www.ruby-forum.com/t/bug-in-multiple-map-resources-has-many/111979/1 "2007-08-14T00:46:28Z")

</div>

Hi,

does map.resources accept more than one :has\_many ?  
there seems to be a path helper only for the last one (eg abc\_bar\_path)

map.resources :abc,  
:has\_one =\> :user,  
:has\_many =\> :foo,  
:has\_many =\> :bar

if so, is this a bug?

(the abc\_user\_path helper is not overwritten tho)

linoj

---

<div class="post-metadata">

**Author:** ![linojon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b3f665/32.png) [@linojon](https://www.ruby-forum.com/u/linojon)\
**Post date:** [August 14, 2007, 12:55am UTC](https://www.ruby-forum.com/t/bug-in-multiple-map-resources-has-many/111979/2 "2007-08-14T00:55:29Z")

</div>

Hi –

On Mon, 13 Aug 2007, linojon wrote:

> if so, is this a bug?
> 
> (the abc\_user\_path helper is not overwritten tho)

No, it’s not a bug. It’s because of how Ruby hashes work. The last  
three lines are all key/value pairs in a hash. Since hash keys are  
unique, you can’t have two :has\_many keys, so the last one clobbers  
the previous one.

David

–

- Books:  
RAILS ROUTING (new! [http://www.awprofessional.com/title/0321509242](http://www.awprofessional.com/title/0321509242))  
RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
- Ruby/Rails training  
& consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![linojon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b3f665/32.png) [@linojon](https://www.ruby-forum.com/u/linojon)\
**Post date:** [August 14, 2007, 4:11am UTC](https://www.ruby-forum.com/t/bug-in-multiple-map-resources-has-many/111979/3 "2007-08-14T04:11:43Z")

</div>

/me slaps forehead

---

<div class="post-metadata">

**Author:** ![linojon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/b3f665/32.png) [@linojon](https://www.ruby-forum.com/u/linojon)\
**Post date:** [August 14, 2007, 1:50am UTC](https://www.ruby-forum.com/t/bug-in-multiple-map-resources-has-many/111979/4 "2007-08-14T01:50:32Z")

</div>

> No, it’s not a bug. It’s because of how Ruby hashes work. The last  
> three lines are all key/value pairs in a hash. Since hash keys are  
> unique, you can’t have two :has\_many keys, so the last one clobbers  
> the previous one.

So, use an array instead. :has\_many =\> [:foo, :bar]

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
