# Add a column "on the fly"

**URL:** <https://www.ruby-forum.com/t/add-a-column-on-the-fly/155153>\
**Category:** Rails\
**Created:** [December 8, 2008, 7:33pm UTC](https://www.ruby-forum.com/t/add-a-column-on-the-fly/155153 "2008-12-08T19:33:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [December 8, 2008, 7:33pm UTC](https://www.ruby-forum.com/t/add-a-column-on-the-fly/155153/1 "2008-12-08T19:33:00Z")

</div>

Hi people,

Does anybody know if it is possible to create columns on the fly…  
so wihout a migration.

I would like to do this so that my customers can create multiple  
languages whitout me generating that language for them.

ohw an second question: could I then check if a particularly column  
exists ? in a table of course 😛

thanxs!

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [December 8, 2008, 10:17pm UTC](https://www.ruby-forum.com/t/add-a-column-on-the-fly/155153/2 "2008-12-08T22:17:28Z")

</div>

On 8 Dec 2008, at 18:33, jeljer te Wies wrote:

> exists ? in a table of course 😛

Well you can of course execute arbitrary sql  
(ActiveRecord::Base.connection.execute), which could add a column (you  
will run into the slight issue that you will need to get all of your  
mongrels/mod\_rails instances etc… to call  
SomeTable.reset\_column\_information). This sounds like a horrifically  
bad idea though

Fred

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [December 8, 2008, 10:28pm UTC](https://www.ruby-forum.com/t/add-a-column-on-the-fly/155153/3 "2008-12-08T22:28:37Z")

</div>

☹ If you put it like that yes !..  
Such a shame ! Beceaus it would have been verry cool  
To add languages on the fly as a customer ☹

Ok wel then I will have to do something with my database design  
So that I would be possible… But it won’t be pritty either ☹

Thanxs allot though for the reply !  
I really apreciate it

Jeljer

Frederick C. wrote:

> On 8 Dec 2008, at 18:33, jeljer te Wies wrote:
> 
> > exists ? in a table of course 😛
> 
> Well you can of course execute arbitrary sql  
> (ActiveRecord::Base.connection.execute), which could add a column (you  
> will run into the slight issue that you will need to get all of your  
> mongrels/mod\_rails instances etc… to call  
> SomeTable.reset\_column\_information). This sounds like a horrifically  
> bad idea though
> 
> Fred

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [December 8, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/add-a-column-on-the-fly/155153/4 "2008-12-08T22:37:27Z")

</div>

On 8 Dec 2008, at 21:28, jeljer te Wies wrote:

> ☹ If you put it like that yes !..  
> Such a shame ! Beceaus it would have been verry cool  
> To add languages on the fly as a customer ☹

I’ve absolutely no idea what you’re doing or trying to do, but I doubt  
that adding columns on the fly is the only way to accomplish what you  
want.

Fred

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [December 9, 2008, 3:47pm UTC](https://www.ruby-forum.com/t/add-a-column-on-the-fly/155153/5 "2008-12-09T15:47:36Z")

</div>

Why can’t you make an additional model “language” and another model of  
“message”, then you only need:

language.rb: has\_many =\> :messages  
message.rb: belongs\_to =\> :language

Then you might have infinite number of languages with infinite number  
of messages ;)))

Good luck! 🙂

On Dec 8, 10:36 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [December 9, 2008, 3:52pm UTC](https://www.ruby-forum.com/t/add-a-column-on-the-fly/155153/6 "2008-12-09T15:52:38Z")

</div>

Yes thanxs !.. I have thought of the same solution.

I now have the following… :

Languages:  
-id  
-name

menus  
-id  
-title  
-languages id

This is a much better solution !! … I really don’t know why haven’t  
thought of it  
sooner.

Thanxs for al the replays guys!.

gr jeljer

PaweÅ‚ K wrote:

> Why can’t you make an additional model “language” and another model of  
> “message”, then you only need:
> 
> language.rb: has\_many =\> :messages  
> message.rb: belongs\_to =\> :language
> 
> Then you might have infinite number of languages with infinite number  
> of messages ;)))
> 
> Good luck! 🙂
> 
> On Dec 8, 10:36 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
