helhum / upload_example

File Upload using Extbase and FAL
101 stars 51 forks source link

foreign_match_fields config: inconsistency? #23

Closed stoppeye closed 8 years ago

stoppeye commented 8 years ago

In the foreign_match_fields config for the image collection you set fieldname as image_collection, which seems to make perfect sense, as this is the name of the field in the database.

I have a similar case in my project and have configured the TCA accordingly and it works. I have noticed however, that if I add a file in the BE, the property name of the extbase model is used and not the field name of the database definition (i.e. in my case otherFiles instead of other_files). So currently I get two different versions in sys_file_reference, depending on whether the file was uploaded from BE or FE.

Both versions seem to work, at least in TYPO3 6.2.18. Is this something to worry about? Could this become a problem at a later stage? Should we do it like the BE, assuming that this is the "right" way? It kinda looks odd to me, not to use the db field name in TCA.

Any recommendations? Thanks!

helhum commented 8 years ago

So currently I get two different versions in sys_file_reference, depending on whether the file was uploaded from BE or FE.

The backend (form engine and data handler) and Extbase both evaluate the TCA. So you must have specified the property name in TCA somewhere. Without seeing the code this is really hard to tell.

stoppeye commented 8 years ago

Ok, I've got a much clearer picture of the problem now. My original interpretation of the observed symptoms was wrong (as I wasn't very familiar with the details of FAL). It's not related to BE or FE, but to BEFORE and AFTER inserting the foreign_match_fields config into the TCA. Because I upgraded an existing extension (TCA created by extension builder), I had to add the foreign_match_fields into the TCA and did it as demonstrated in your example. It turns out that the default behaviour of TYPO3 is different than I had expected. If NO foreign_match_fields config is given, the db field other_files gets written as otherFiles in sys_file_reference.fieldname. After adding the foreign_match_fields config, everything works consistently. But all existing data that was created before the upgrade seemed to have disappeared, because the data in the TCA and the db didn't match anymore. Once you're aware of the problem, it all makes perfect sense, but it took me a while to find out... I personally find the default behaviour of TYPO3 a bit strange, because nowhere in the TCA or the db is the camel-cased version of property names used, so it seems counter-intuitive to do so. This is just something to keep in mind when upgrading existing extensions with existing data.