adding dynamic field to a model ...

Damian Rr wrote:

second: the users should be able to add new fields to that model, for
example: the model 'person' may have 2 fields, let say: 'name' and
'age', the basic idea is to give the user the ability to create new
fields like 'sex' and 'occupation' if he like to do so, i wouldn't like
to do ALTER TABLE to solve this .... any idea will be most welcome ...

I have a plugin that I developed that will help handle this problem. You can find out about it at:

It basically does what nathaniel described but also has some method_missing magic to allow you to do:

joe.gender = 'Male';

Even though "gender" is not a real attribute on the peoples table. It is still what I consider "beta" software but it has been used successfully in two project. I just need to clean up the documentation and then I probably consider it out of "beta".

Also as nathaniel said this will basically make your data not very accessible. Doing queries on these dynamic fields is difficult. But it is nice when you need to be able to just store and retrieve a bunch of data.


Eric Milinda wrote:

I can not download plugin.

It is in the SCM.

TO avoid the difficult queries... can I use alter table? is it efficient?

You could but that is now what that plugin does. The main problem with ALTER TABLE is that you would need to have the model reload the column information before any query. Also all objects will share the same set of possible columns while storing it in a thin table (as my plugin does) allows each object to determine what columns are available/used.