My project has a requirement to support configurable forms format. What I mean by that is the user can add ‘n’ number of columns to a form(to design it) and then the column data has to be saved in the db. Later on I also want to query on those columns for where clause..
But since the number and type of columns is not fixed, how do I design my database to support such a functionality?? I am using Java as my programming language and PostgreSQL db.
This is not as hard as it sounds. You just need a separate table for the columns in the form and for the value in each entity (one instance of the filled in form). This is sometimes call and Entity Attribute Value model.
form
form_column
entity
entity_attribute
To search for entities, your query screen can build up the SELECT statement by adding “OR (entity_attribute.entity_id=entity.entity_id and entity_attribute.attribute=FOO and entity_attribute.value=BAR)” subclauses to the WHERE clause.
An alternate approach would be to store the form design and the entities (filled in forms) as XML. From there you can use XMLBeans or a DOM parser to work with the entities.