ctsit / redcap_entity

Other
4 stars 8 forks source link

Unable to save entity with integer in a 'text' type column #33

Open 123andy opened 2 years ago

123andy commented 2 years ago

In validateProperty we take a pretty strict definition (by php standards) for the columns defined as 'text'. A php number will be rejected. In my case, I had an array key that was numeric (for one record_id) and when I tried to save it into an entity defined as a 'text' field (as some other records are alpha) - it failed.

I had to explicitly cast it as a string in the payload to the entity before trying to create the new record. One might consider allowing numeric integers as well to be more 'REDCap-like'...

            case 'text':
                if (!is_string($value)) {
                    return false;
                }
                break;

Or, am I missing something here...

123andy commented 2 years ago

Related -- is there a better way to handle this kind of an error? When I I do:

$entity = $factory->create('my_object', $payload);

If I get a 'false' back, I know it failed for some reason but I'm not sure how I could get the list of $errors from the entity object?