diego:
>every single filled field will be stored in the database. so i will
>have the records vertically not horizontally right?
Right
>
>1. what about searching?
>in a regular schema we could do something like
>select * from submissions where form_id = n AND name LIKE '%maria%'
>
>with this shcema that will be impossible
I am not sure what you consider a 'regular' schema. The one I gave is,
in my opinion, quite regular. Of course, you can't have a query like
the above.
If you gave me a result you would like to retrieve, I may give you the
query, based upon a database derived from the ER model I painted.
It would be something like
SELECT ffx.fieldcontents FROM filledfields ff
INNER JOIN fields f ON f.fieldid=ff.fieldid
INNER JOIN fx.fields fx ON fx.formid=f.formid
INNER JOIN ffx.filledfields ON ffx.fieldid=fx.fieldid
WHERE ff.fieldcontents LIKE "%maria%"
AND f.fieldname = "name"
ORDER BY fx.fieldname
Of course, you'd only need a handful of different queries, and you
would prepare each just once, so this looks worse than it is.
>2. what about performance?
>is a good practice to store records in that way?
Well, I'm still in the phase of setting up an ER model, not building
the database, so we're not "storing" anything, yet. Our first concern
is to have a normalized model and include all possible functionality
that you require.
>
>what do you think about this?
>
>table submissions
>- id
>- form_id
>table filled_fields
>- id
>- form_id
>- field_id
>- value (data entered by the user)
>- submissions_id
This would be redundant. If you have filled_fields.submissions_id, you
don't need form_id, because in your model, each submission is already
connected to only one form.
Also, if you have field_id, you don't need form_id, because each field
is only related to one form.
>
>how can i loop through all records and its fields?
In an RDBMS, you don't "loop through" data. Looping is something an
application would do. The database query returns a result set, which
you may transform to an array in your application and go from there. If
your application is a website or web-app, you may want your API to
return a json-object and use that to present the data.
>
>SELECT * FROM submissiones WHERE id = 1
What are you trying to retrieve here? All you would get are the values
of all attributes/fields of the submission (e.g. submission date, time
and IP address). If you want values from 'form', 'field' or
'filledfield', you need to join tables.
>....
>
>so many questions.
There are more important questions that have to be answered, first. For
instance:
- what do you want to happen, if a user deletes a field from a form,
after 100 submissions have been entered already? Do you want the
submitted values for that field to be destroyed?
If so, the user can't undo such action, which may be a problem (but it
would keep your database clean and simple). If not, then you need to be
able to switch field definitions to active/not-active and present forms
based upon the value of this switch. 'Deleted' fields would remain in
the database, and so would the submitted data.
- how do you want to map values to the field type? Do you want to store
date values as a mySql-DATE-field, for instance?
If so, what do you want to happen with the submitted data, if a user
changes the field type?
- do you need to know who created forms and fields? Do you need to know
where the forms are used (for instance for security reasons)? If so,
you need relevant entities in your ER model.
--
Erick