# Foreign\_key problems

**URL:** <https://www.ruby-forum.com/t/foreign-key-problems/133619>\
**Category:** Rails\
**Created:** [April 2, 2008, 2:24am UTC](https://www.ruby-forum.com/t/foreign-key-problems/133619 "2008-04-02T02:24:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rashantha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@rashantha](https://www.ruby-forum.com/u/rashantha)\
**Post date:** [April 2, 2008, 2:24am UTC](https://www.ruby-forum.com/t/foreign-key-problems/133619/1 "2008-04-02T02:24:41Z")

</div>

model user  
id (automatic primary)  
fname  
lname  
user\_rrid (foreign key) - string “123456”

model email  
id (automatic primary)  
e\_addresss  
user\_rrid (foreign key) - string “123456”  
e\_type

i would like to find a user by fname  
@user = User.find\_by\_fname(“John”)  
then use…  
@user.email.e\_address  
@user.email.e\_type

i would also like to go the other way. search email based on e\_address  
and find the user.

can you please show how the user.rb and email.rb files should be set  
up. i have looked thru the docs and googled and everything i try does  
not work.  
i have tried using foreign\_key but it does not work.  
thanks.
