Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen:
Registering Doctrine Type Mappings for standalone migrations
Nov 18, 2014 @ 16:50:47

In a previous post Rob Allen showed you how to use Doctrine migrations as a standalone tool in your applications. In this new post he takes that a step further and shows you how to use the type mapping functionality (allowing for more customized column handling).

Shortly after starting to use Doctrine Migrations as a standalone tool in my project, I came across this error message [about an unknown database type "bit"]. This means that I have a column in my database of type bit which is used for booleans in SQL Server, but confuses the MySQL platform as it's not a default mapping. To support this, you need to modify the database connection's Platform object to know about the new mapping. However, with the setup that I'm using, I didn't have access to the connection object that's automatically created in the Migrations AbstractCommand object. After poking around in the code for a bit, I discovered that the solution is to create the connection object myself and then attach it as a new helper to the ConsoleApplication object.

He includes the code you'll need to add to your "migrations.php" file to set up the mapping relating his "bit" type example back to a "boolean" type. While this specific example is for the "bit" mapping, it shows how any mapping type can be added in. Finally he adds the connection (the one he set the type on) to enable it to be included in the helper set collection.

tagged: register type migration doctrine database tutorial custom mapping

Link: http://akrabat.com/php/registering-doctrine-type-mappings-for-standalone-migrations/


Trending Topics: