Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.2.0-ALPHA1
-
Fix Version/s: 1.2.0-ALPHA3
-
Component/s: Record
-
Labels:None
Description
We are generating our entity classes from the database. By doing so, we get a nicely separated set of base record classes and derived record classes where we can implement our logic. The case is, that we want to add validators to about every field there is. The only way that we can do that right now, is by overriding the setUp() method, calling parent::setUp() and providing new column definitions using addColumn(). By doing so, we do have to include the options that were so nicely automatically determined from the database. If we now update our schema in the db and regenerate the base record classes, we might have to manually update addColumn() calls in derived records.
To make it possible to fully separate the automatic and manual code, we were looking for a method to tweak an already existing table, but we couldn't find such method. Therefore, we implemented one ourselves.
A practial usage example. This is what we had to write in the derived class (not a validator example, but the idea is the same of course: tweak or add a column option):
// Override the "info" column definition. We want this field to be // an object field, so we can store a serialized object in it. $this->hasColumn('info', 'object', null, array( 'type' => 'object', 'fixed' => false, 'unsigned' => false, 'notnull' => true, 'primary' => false, ));
This is what we write now:
$this->setColumnOption('info', 'type', 'object');
Please, consider adding the proposed change from the attached diff file. Of course, also let me know if there is a better way to handle this.
Issue Links
- relates to
-
DC-63
Option to additionally add validators to fields
-
Diff for adding a setColumnOption() method to Doctrine_Record.