collection_select question

Hello!

New to ruby on rails, so I hope this isn't a stupid question (great way to start a post ;)). Basically I'm trying to avoid making a bunch of different columns in my db table by having my collection_select concatenate the ID value it returns to a single text field (for instance, the collection_select will return a footnote ID, and I would like to keep it in a job column called footnote) with comma's in between because each job has multiple footnotes.

Is there any way I can accomplish this ? Ideally I would like to put comma's in between so I can break it apart in another area of my program.

Thank you for any help.

Bee Dubya wrote:

Hello!

New to ruby on rails, so I hope this isn't a stupid question (great way to start a post ;)). Basically I'm trying to avoid making a bunch of different columns in my db table by having my collection_select concatenate the ID value it returns to a single text field (for instance, the collection_select will return a footnote ID, and I would like to keep it in a job column called footnote) with comma's in between because each job has multiple footnotes.

DO NOT DO THAT. You need two tables with a has_many/belongs_to relationship. You should never ever put multiple values in one field.

Is there any way I can accomplish this ? Ideally I would like to put comma's in between so I can break it apart in another area of my program.

Don't. Read up on proper database normalization, and do it right.

Thank you for any help.

Best,

Marnen Laibow-Koser wrote:

Bee Dubya wrote:

Hello!

New to ruby on rails, so I hope this isn't a stupid question (great way to start a post ;)). Basically I'm trying to avoid making a bunch of different columns in my db table by having my collection_select concatenate the ID value it returns to a single text field (for instance, the collection_select will return a footnote ID, and I would like to keep it in a job column called footnote) with comma's in between because each job has multiple footnotes.

DO NOT DO THAT. You need two tables with a has_many/belongs_to relationship. You should never ever put multiple values in one field.

Is there any way I can accomplish this ? Ideally I would like to put comma's in between so I can break it apart in another area of my program.

Don't. Read up on proper database normalization, and do it right.

Thank you for any help.

Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org

In connection with this, and at the risk of reviving a dead thread: a big part of database normalisation is atomising your data. This enables you to better acclimate your application to future alterations and more effective database requests. Searching is a good example of this - I am simply reinforcing Marnen's point regarding database normalisation.