I have a database that I am trying to move into SilverStripe's ORM. Some of the fields store numeric data, but use null to signify that a value was not available. Can I do this within SilverStripe?
I have created a model for the object and a form to enter data, but when I try to store the data, my null values are being altered. I have tried PHP's NULL constant and the string "null".
FYI, the form data is only partial, and the remaining values are calculated based on the form data. The fields that may be null are all calculated fields, so I am not entering "null" in a text box, it is being added programmatically to the array of data. That array is passed at instantiation, and then written to the database (pseudocode):
$calculated_data = calculations($form_data);
$snapshot_data = array_merge($form_data, $calculated_data);
$snapshot = new Snapshot($snapshot_data);
I did find that setting the field default to NULL (using phpMyAdmin) solves part of my problem, as I am then able to pass "" or NULL and the resulting field is saved as NULL. But... /dev/build changes the field to NOT NULL and my data is altered.
How can I make this work? Perhaps more importantly, is using NULL in the database for this purpose bad design (if so, what should I do about it)?