Welcome Guest, Not a member yet? Register   Sign In
User defined extra fields
#1

[eluser]Eric Barnes[/eluser]
Hi,

I am working on a new script and I want to allow the admins to create extra fields for a table. The trick is I want this data to be pulled out and also be sortable when viewing a list of results.

Currently I came up with the idea to create a secondary table something like "field_data" which by default only includes the unique id and the id of the relationship. Then when an admin creates a new field it adds a new field to this table.

The other idea I had was to create a table like this:
table field_data
fields: id, rel_id, field_id, field_value

But that seems to add a lot of complexity when generating search results and trying to resort data from this table.

Does anyone have any other ideas that I may not be thinking about?
#2

[eluser]Phil Sturgeon[/eluser]
You have picked the way I would normally do it, but you could look into using DBForge. Would let you literally add a new field if you want a new field. Probably not the best method though.
#3

[eluser]TheFuzzy0ne[/eluser]
Just try not to forget that you'll need to track these extra columns somewhere, so that they can be removed. Extending the table seems like a logical idea to me, as it doesn't needlessly complicate the getting of data.

However, there is a down side. You'll need to be careful when creating new columns if you plan on indexing them. Because of this, it might make more sense to do it the other way round. At least that way, you've already set up the indexing.

So honestly, I have no idea which route I'd take.
#4

[eluser]Eric Barnes[/eluser]
Very good points. My idea was to have have three tables:
extra_fields - Extra field settings name, type, validation, etc.
content - Global Data
content_field_data - Extra content field data

Then create the new fields in the content_field_data table and use something like "ext_field_1, ext_field_2" where the number is the relationship id from the extra fields. So it would make getting the ones related easier and also easy to remove.

I haven't thought about the indexing yet but that will need to be thought through as well.




Theme © iAndrew 2016 - Forum software by © MyBB