2

I'm developing an Apigility driven web application based on Zend Framework 2. For the model layer I'm using the ZfcBase DbMapper.

Currently the columns in my DB tables are named exactly like the correspondent model properties. For both I'm using camelcased notation (it was the first temporary solution). Now I'd like to correct the naming of the columns and make them undescored.

How to do this without using an ORM (like doctrine)? I guess, I'll need the Filters (Zend\Filter\Word\CamelCaseToUnderscore, Zend\Filter\Word\UnderscoreToCamelCase, Zend\Filter\StringToLower or just strtolower(...)). Well, but where and how should they be utilized here?

automatix
  • 14,018
  • 26
  • 105
  • 230

1 Answers1

3

You should update all database column names with the new under_score naming convention, the database adapter will automatically query the database for this information.

Then in order to 'map' the new column_name to object property propertyName the mapper requires an object hydrator.

The default mapper is ClassMethods, which out of the box supports the conversion to underscore separated keys, using the filter classes you mentioned.

Therefore the naming should just work, you will only need to pass in true to the constructor of the hydrator (underscoreSeparatedKeys), which can be done very easily when you create your mapper.

AlexP
  • 9,906
  • 1
  • 24
  • 43
  • 1
    I've just renamed the columns back (made their names underscored again). And it works. I could swear, that this didn't work before -- it was the reason, why I first made the column names camelcased. Magic... :) Anyway, it works. Thank you for the good explanation! – automatix Jan 19 '15 at 16:29