spadefoot / kohana-orm-leap

An ORM module for the Kohana PHP framework that is designed to work with all major databases.
http://spadefoot.github.io/kohana-orm-leap/
100 stars 25 forks source link

Can't initialize model, if the enum is set. #66

Closed taai closed 11 years ago

taai commented 11 years ago

When the field in model is set to be an enum string, the Kohana_BadData_Exception is being thrown. Kohana_BadData_Exception [ 0 ]: Message: Unable to set default value for field. Reason: Value failed to pass validation constraints.

I can't even do this:

<?php
$car = new Model_Leap_Car();

It's because in DB_ORM_Field_String the value is set to empty string and in that way the validation get's called right away and in_array($value, $this->metadata['enum']) is being checked. https://github.com/spadefoot/kohana-orm-leap/blob/3.2/develop/classes/base/db/orm/field/string.php#L80

I haven't tried other field types, but it's possible that this bug exists in other field types too.

Possible solutions

  1. Before setting the value to an empty string in the __construnct(), check if there is no enum set.
  2. Throw an exception that the default value must be set. I'm really not sure for this...