Jump to content

Question about PW architecture for fields


jordanlev
 Share

Recommended Posts

I love how relatively simple PW is at its core, and how everything is built up from that foundation in an elegant way.

Now that I've spent more time digging into the code and architecture, there is one thing that strikes me as curious: why does each field that you create get its own database table, instead of there just being 1 table for each field *type*? It seems to me that the schema of each field's database table would be exactly the same for all fields of 1 type, so what is the benefit of this extra layer of abstraction (separate tables for each field instance)?

   -Jordan

Link to comment
Share on other sites

The short answer would be flexibility. Maybe you have multiple image fields with different usecases / single or multiple. Now you need to extend one of the image fields, so that it would feature a star rating for each image, how much people voted and the max votes in one day. With the single table mentality you can easily extend the one field with more columns to be used by the extended image-rating-field. 

Backwards it's the same. Maybe you have a multilanguage textfield and you want to switch it back to singlelanguage. Now you can easily delete the language specific columns without worrying about other fields. It also makes stuff more clear in the database. If your textfields would all share the same table, you would get lot's of empty fields for the singlelanguage ones, if only one is multilanguage.

Also you see, even the simple textfields don't really share one schema, like you said. 

Link to comment
Share on other sites

@mr-fan, thanks for the links... that is a fascinating discussion.

@LostKobrakai , thanks for the info about the same field type having different schemas... I was not aware this was an option.

Seems to me that the assumption in Processwire is that all fields have the potential to be "global" (available to all pages), hence this architectural decision. I'm not sure I agree that that's the best approach, but I do see the logic behind it. Also as with everything it depends on the kinds of sites one is building.

Anyway, thanks for the info guys, much appreciated!

  • Like 1
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...