I’m looking at using DataMapper ORM with CodeIgniter, but have a scenario where the database structure is poorly formed.
I’d like to be able to configure my model to map the database field names, to something more logical. Then, when we get around to updating the database structure, I can just update the model, and all the referencing code will continue to work.
Is this possible with DataMapper ORM?
Yes it is possible. I can explain the logic and how your can tackle the problem using a custom core class for the codeigniter application.
Create a file inside application/core/ and label it Mapdm.php
write the following inside the file.
To use this in your controller, simply instantiate this class as show below inside the controller constructor class. To simplify table field map data in the array, you may choose to store the array data inside a custom config file.
example. map_field_config.php (file contents)
controller file setup
I have not tested this code, however I just wrote it to give you an idea. It is like creating a wrapper object for Datamapper model and calling the methods and properties using the wrapper. The wrapper should always check and return the correct table field name to the datamapper object.