# Table associations

**URL:** <https://www.ruby-forum.com/t/table-associations/96398>\
**Category:** Rails\
**Created:** [June 28, 2006, 5:05pm UTC](https://www.ruby-forum.com/t/table-associations/96398 "2006-06-28T17:05:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fernando](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/779978/32.png) [@fernando](https://www.ruby-forum.com/u/fernando)\
**Post date:** [June 28, 2006, 5:05pm UTC](https://www.ruby-forum.com/t/table-associations/96398/1 "2006-06-28T17:05:04Z")

</div>

I have 2 tables

* * *

cursos  
id  
name

* * *

turmas  
id  
cursos\_id  
name

Model turma

belongs\_to :cursos

Model curso

has\_manay :turma

TurmasController  
scaffold:turma

Ok, it’s works, but I can’t select, the Curso in curso ID field,  
it’s only display the field name…

what can be wrong?

---

<div class="post-metadata">

**Author:** ![fernando](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/779978/32.png) [@fernando](https://www.ruby-forum.com/u/fernando)\
**Post date:** [June 28, 2006, 5:16pm UTC](https://www.ruby-forum.com/t/table-associations/96398/2 "2006-06-28T17:16:01Z")

</div>

On 6/28/06, Fernando [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> cursos\_id  
> has\_manay :turma  
> has\_many :turmas

---

<div class="post-metadata">

**Author:** ![fernando](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/779978/32.png) [@fernando](https://www.ruby-forum.com/u/fernando)\
**Post date:** [June 28, 2006, 6:26pm UTC](https://www.ruby-forum.com/t/table-associations/96398/3 "2006-06-28T18:26:58Z")

</div>

## not working yeat …

## Table Cursos id name

## Table Turmas id name cursos\_id

## Model Turma class Turma \< ActiveRecord::Base belongs\_to :cursos end

## Model Curso class Curso \< ActiveRecord::Base has\_many :turmas end

## turmas\_controller class TurmasController \< ApplicationController scaffold:turma end

When I click in the link NEW TURMA  
the form display only 1 field…

the name field.

And my Cursos Table is not empty.

---

<div class="post-metadata">

**Author:** ![fernando](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/779978/32.png) [@fernando](https://www.ruby-forum.com/u/fernando)\
**Post date:** [June 28, 2006, 6:44pm UTC](https://www.ruby-forum.com/t/table-associations/96398/4 "2006-06-28T18:44:06Z")

</div>

I’ve come in late to this discussion, so I haven’t seen what messages  
have already been sent back and forth. Sorry if I’m going to cover  
anything that’s already been brought up…

On Jun 28, 2006, at 12:26 PM, Fernando wrote:

> ## cursos\_id
> 
> And my Cursos Table is not empty.

What you are seeing is not an unexpected result. Unfortunately, you  
are using the scaffold controller method, and not a fully generated  
scaffold, from a call to:

./script/generate scaffold Turma

If you were to generate the scaffold, you would see that when the new  
(also the edit) form is built that it only contains entry fields for  
those columns that a user would normally enter data into. Rails calls  
these the “content columns” of a given ActiveRecord model class. ID  
columns, whether they are primary key fields (ie. id) , or foreign  
key fields (ie. cursos\_id) are not considered content columns by  
Active Record.

Additionally, the built in scaffolding is only for building a basic  
CRUD structure for a single model class. There are no facilities,  
though the build-in scaffolding, to do anything with associated tables.

This is why what you are seeing is, in fact, what you are supposed to  
be seeing.

-Brian
