# Changing foreign key values

**URL:** <https://www.ruby-forum.com/t/changing-foreign-key-values/188542>\
**Category:** Rails\
**Created:** [May 13, 2010, 4:38pm UTC](https://www.ruby-forum.com/t/changing-foreign-key-values/188542 "2010-05-13T16:38:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam\_wead](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@adam\_wead](https://www.ruby-forum.com/u/adam_wead)\
**Post date:** [May 13, 2010, 4:38pm UTC](https://www.ruby-forum.com/t/changing-foreign-key-values/188542/1 "2010-05-13T16:38:52Z")

</div>

Hi all,

I have a simple inventory application that consists of rooms with many  
items (computers, printers, etc). I’d like to create a form for  
moving an existing item to another room. This means changing the  
value of the room\_id foreign key in the particular row of the item  
table.

If I wasn’t using Rails, I’d probably do something like assemble a  
hash of key = room name pairs with some SQL, and make a form with a  
drop-down that allows you to choose another room name and executes  
another sql statment that updates the item record with the new foreign  
key. Does that same strategy still apply, or is there a more “Rail-  
esque” way of doing that?

Just wondering…

thanks!

…adam
