jordanlev Posted October 19, 2014 Share Posted October 19, 2014 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 More sharing options...
mr-fan Posted October 20, 2014 Share Posted October 20, 2014 Some reading stuff.... https://processwire.com/talk/topic/3189-one-table-per-field-rationale-and-impact/ and from ryan... https://processwire.com/talk/topic/2387-the-structure-of-fields-and-templates/?p=22762 2 Link to comment Share on other sites More sharing options...
LostKobrakai Posted October 20, 2014 Share Posted October 20, 2014 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 More sharing options...
jordanlev Posted October 20, 2014 Author Share Posted October 20, 2014 @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! 1 Link to comment Share on other sites More sharing options...
Recommended Posts