# User-defined columns

**URL:** <https://www.ruby-forum.com/t/user-defined-columns/52313>\
**Category:** Rails\
**Created:** [January 12, 2006, 7:26pm UTC](https://www.ruby-forum.com/t/user-defined-columns/52313 "2006-01-12T19:26:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [January 12, 2006, 7:26pm UTC](https://www.ruby-forum.com/t/user-defined-columns/52313/1 "2006-01-12T19:26:25Z")

</div>

I am breaking ground on a new project and one of the issues I expect to  
encouter  
is the ability of users to define their own columns. For example, one of  
the  
features of this application will be the ability to store information  
about  
people’s skills and then search for and schedule them based on this  
information.  
Since every organization’s needs are different, it would be ideal to  
allow each  
organization to extend the basic schema dynamically.

Has anyone else dealt with this scenario in Rails? Are there advantages  
to using  
a particular database for this?

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [January 12, 2006, 7:38pm UTC](https://www.ruby-forum.com/t/user-defined-columns/52313/2 "2006-01-12T19:38:29Z")

</div>

Jason C. wrote:

> I am breaking ground on a new project and one of the issues I expect to encouter  
> is the ability of users to define their own columns. For example, one of the  
> features of this application will be the ability to store information about  
> people’s skills and then search for and schedule them based on this information.  
> Since every organization’s needs are different, it would be ideal to allow each  
> organization to extend the basic schema dynamically.
> 
> Has anyone else dealt with this scenario in Rails? Are there advantages to using  
> a particular database for this?

Why not instead use a tagging system? You can store arbitrary key/value  
pairs in the database in a generic way, e.g., have a table called  
“tags.” There are plenty of resources out there about how to do this,  
just search Google for Rails+tagging.

–  
Jesse F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
University of Chicago - NSIT Web Services  
AIM: farmerje  
Jabber: removed\_email\_address@domain.invalid  
Phone: (773)363-1058

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [January 13, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/user-defined-columns/52313/3 "2006-01-13T17:10:20Z")

</div>

Jesse F. \<farmerje@…\> writes:

> Why not instead use a tagging system? You can store arbitrary key/value  
> pairs in the database in a generic way, e.g., have a table called  
> “tags.” There are plenty of resources out there about how to do this,  
> just search Google for Rails+tagging.

Tagging is an interesting option that I hadn’t considered. I don’t have  
the  
requirements solidified yet, but it might be sufficient. However, simple  
key/value pairing might not offer enough control. For instance, it might  
be  
necessary to indicate level of skill/proficiency, meaning that the  
end-user  
could define custom attributes with custom defined values. Is that  
something  
that tagging would provide?

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [January 13, 2006, 5:35pm UTC](https://www.ruby-forum.com/t/user-defined-columns/52313/4 "2006-01-13T17:35:14Z")

</div>

Jason C. wrote:

> Jesse F. \<farmerje@…\> writes:
> 
> > Why not instead use a tagging system? You can store arbitrary key/value  
> > pairs in the database in a generic way, e.g., have a table called  
> > “tags.” There are plenty of resources out there about how to do this,  
> > just search Google for Rails+tagging.
> 
> Tagging is an interesting option that I hadn’t considered. I don’t have  
> the  
> requirements solidified yet, but it might be sufficient. However, simple  
> key/value pairing might not offer enough control. For instance, it might  
> be  
> necessary to indicate level of skill/proficiency, meaning that the  
> end-user  
> could define custom attributes with custom defined values. Is that  
> something  
> that tagging would provide?

Polymorphic associations (from edgerails) might also work well for this.  
However…

There is no reason that rails can’t add/drop table columns through SQL  
calls. Since ActiveRecord is good at picking up things from the table  
structure, it would probably work pretty well. You would have to do  
some introspection to know what columns had been added, but that is  
pretty easy with RoR.

\_Kevin

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [January 15, 2006, 5:07am UTC](https://www.ruby-forum.com/t/user-defined-columns/52313/5 "2006-01-15T05:07:53Z")

</div>

Larry W. \<larrywright@…\> writes:

> * * *
> 
> Rails mailing list  
> Rails@…  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

I share that concern as well. The application I am designing would also  
be a  
multi-user database. I guess it would be possible to create a new  
instance of  
the application for each customer, but surely that would become  
unmanageable  
with any level of success.

For sake of discussion, can anyone provide a sample of how creating  
columns via  
ActiveRecord might be implemented? I am fairly new to Rails, so I’m not  
completely familiar with how you do introspection and such. In C# I  
handle  
Reflection with precision and ease, but these dynamic languages are  
still a  
mental stretch for me.

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [January 14, 2006, 9:01pm UTC](https://www.ruby-forum.com/t/user-defined-columns/52313/6 "2006-01-14T21:01:21Z")

</div>

On 1/13/06, Kevin O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \_Kevin
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

I’ve got a similar need potentially, so I’m glad to see some discussion  
around this topic. The only issue with adding the fields dynamically is  
how  
to handle multi-user systems. Take Basecamp for example, if they allowed  
for  
adding custom fields. Certainly there is only one database for everyone  
using Basecamp, as doing otherwise would likely not be feasible. So how  
do  
you handle it for these situations?

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [October 17, 2006, 9:53am UTC](https://www.ruby-forum.com/t/user-defined-columns/52313/7 "2006-10-17T09:53:25Z")

</div>

I too posted a similar problem. Has anyone found a solution or has any  
clues?

tia,

Roberto

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [April 4, 2006, 5:20pm UTC](https://www.ruby-forum.com/t/user-defined-columns/52313/8 "2006-04-04T17:20:32Z")

</div>

jason cartwright wrote:

> Larry W. \<larrywright@…\> writes:
> 
> > * * *
> > 
> > Rails mailing list  
> > Rails@…  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> I share that concern as well. The application I am designing would also  
> be a  
> multi-user database. I guess it would be possible to create a new  
> instance of  
> the application for each customer, but surely that would become  
> unmanageable  
> with any level of success.
> 
> For sake of discussion, can anyone provide a sample of how creating  
> columns via  
> ActiveRecord might be implemented? I am fairly new to Rails, so I’m not  
> completely familiar with how you do introspection and such. In C# I  
> handle  
> Reflection with precision and ease, but these dynamic languages are  
> still a  
> mental stretch for me.

I just found this thread after posting a similar topic. Was any decent  
solution found for the problem of user-defined columns?

Allowing the application to add/remove columns is not an option for me.  
The database will be shared among many users.

Tagging as I understand it doesn’t provide what I’m looking for either.  
I’ll need a key/value pair for rows in a database. The keys will be  
user-defined for the entire account and will only be mutable by the  
administrator of that particular account.

Jake
