# Scaffolding on a table with a foreign key

**URL:** <https://www.ruby-forum.com/t/scaffolding-on-a-table-with-a-foreign-key/81046>\
**Category:** Rails\
**Created:** [January 3, 2007, 10:55am UTC](https://www.ruby-forum.com/t/scaffolding-on-a-table-with-a-foreign-key/81046 "2007-01-03T10:55:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisfinne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f1d935/32.png) [@chrisfinne](https://www.ruby-forum.com/u/chrisfinne)\
**Post date:** [January 3, 2007, 10:55am UTC](https://www.ruby-forum.com/t/scaffolding-on-a-table-with-a-foreign-key/81046/1 "2007-01-03T10:55:51Z")

</div>

Hi,  
sorry if it is too easy a question but:

I have a table with a foreign key in it. When I apply a scaffold to it,  
it does not show the foreign column in list, edit etc.  
How can I make it show the foreign column?

Chris

---

<div class="post-metadata">

**Author:** ![chrisfinne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f1d935/32.png) [@chrisfinne](https://www.ruby-forum.com/u/chrisfinne)\
**Post date:** [January 3, 2007, 1:00pm UTC](https://www.ruby-forum.com/t/scaffolding-on-a-table-with-a-foreign-key/81046/2 "2007-01-03T13:00:06Z")

</div>

Chris F. wrote:

> I have a table with a foreign key in it. When I apply a scaffold to it,  
> it does not show the foreign column in list, edit etc.  
> How can I make it show the foreign column?  
> Scaffold does not show columns of a table that a foreign key refers to.  
> You will need to add this support in your model (belongs\_to,  
> has\_one/many), view (list, new, show, delete).rhtml files and link the  
> tables with their foreign key relationships accordingly in your  
> controller. If you want an easy way out, try the plugin  
> scaffolding\_extensions or streamlined.  
> Send your model details, and tell us what you intend to do, someone  
> over here can help you.

---

<div class="post-metadata">

**Author:** ![chrisfinne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f1d935/32.png) [@chrisfinne](https://www.ruby-forum.com/u/chrisfinne)\
**Post date:** [January 25, 2007, 11:52am UTC](https://www.ruby-forum.com/t/scaffolding-on-a-table-with-a-foreign-key/81046/3 "2007-01-25T11:52:07Z")

</div>

Hi ,  
I used scaffolding\_extensions.

There is a problem:  
In, for example create, the foreign key is shown as the foreign id. But  
I want to show the foreign id’s name. How do I change it so that it is  
the name attribute of the foreign key and not it’s id?

Thankyou  
Chris.

---

<div class="post-metadata">

**Author:** ![chrisfinne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f1d935/32.png) [@chrisfinne](https://www.ruby-forum.com/u/chrisfinne)\
**Post date:** [January 25, 2007, 7:13pm UTC](https://www.ruby-forum.com/t/scaffolding-on-a-table-with-a-foreign-key/81046/4 "2007-01-25T19:13:31Z")

</div>

On 1/25/07, Chris F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi ,  
> I used scaffolding\_extensions.
> 
> There is a problem:  
> In, for example create, the foreign key is shown as the foreign id. But  
> I want to show the foreign id’s name. How do I change it so that it is  
> the name attribute of the foreign key and not it’s id?

In the associated model:

def scaffold\_name  
name\_column  
end

Actually, scaffolding\_extensions defaults scaffold\_name first to  
self[:name] and then to id, so in your schema the column you want to  
use must not be named “name”. Just put the name of the column that  
contains the name you want to see in the select box.

Jeremy
