# Habtm relation, cannot populate join table

**URL:** <https://www.ruby-forum.com/t/habtm-relation-cannot-populate-join-table/187305>\
**Category:** Rails\
**Created:** [April 21, 2010, 2:09pm UTC](https://www.ruby-forum.com/t/habtm-relation-cannot-populate-join-table/187305 "2010-04-21T14:09:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![veena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/51bf81/32.png) [@veena](https://www.ruby-forum.com/u/veena)\
**Post date:** [April 21, 2010, 2:09pm UTC](https://www.ruby-forum.com/t/habtm-relation-cannot-populate-join-table/187305/1 "2010-04-21T14:09:00Z")

</div>

Hai friends,  
I hav two models related with habtm

class User \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :station,  
:join\_table =\> “stations\_users”,  
:foreign\_key =\> “user\_id”,  
:association\_foreign\_key =\> “station\_id”

class Station \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :user  
end

When i create a new user its user\_id and the station \_id is not inserted  
into the “stations\_users” table.I hav used scaffolding 4 creating these  
two models.How can i insert the fields for the join table also when a  
user is created?  
Can any one help me?

Thanks and regards,  
Veena
