# Question about Nested Join Tables

**URL:** <https://www.ruby-forum.com/t/question-about-nested-join-tables/184532>\
**Category:** Rails\
**Created:** [March 4, 2010, 12:50am UTC](https://www.ruby-forum.com/t/question-about-nested-join-tables/184532 "2010-03-04T00:50:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![acgreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3bc359/32.png) [@acgreen](https://www.ruby-forum.com/u/acgreen)\
**Post date:** [March 4, 2010, 12:50am UTC](https://www.ruby-forum.com/t/question-about-nested-join-tables/184532/1 "2010-03-04T00:50:10Z")

</div>

I have five tables that I am trying to get to work nicely together but  
may  
need some help.

I have three main tables: accounts, members and roles. With two join  
tables  
account\_members and account\_member\_roles.

The accounts and members table are joined by account\_members (fk  
account\_id  
and member\_id) table (many-to-many). No problem.

The other 2 tables are the problem (roles and account\_member\_roles).

A member of an account can have more than one role and I have the  
account\_member\_roles (fk account\_member\_id and role\_id)  
table joining the account\_members join table and the roles table.

That seems logical (an account\_member can have many roles  
(account\_member\_roles), unless anyone thinks differently. What I’d like  
to  
be able to do is when creaeting an account, for instance, I would like  
@account.save to include the roles and update the account\_member\_roles  
table  
neatly … but through the account\_members join table.

accept\_nested\_attributes\_for :members exist in the account.rb so that’s  
no  
problem but I’d like a nested/nested accept\_nested\_attributes\_for  
:account\_member\_roles in account.rb

I’ve tried an accept\_nested\_attributes\_for in the join model  
account\_member.rb but it doesn’t work (even though logically that’s how  
it  
is)

It’s late so maybe I’m overlooking something simple here or maybe  
there’s a  
better approach.

CIA

-ants
