Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
123andy opened this issue Dec 20, 2021 · 1 comment
Open

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

123andy opened this issue Dec 20, 2021 · 1 comment

Comments

@123andy
Copy link
Contributor

123andy commented Dec 20, 2021

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
Copy link
Contributor Author

123andy commented Dec 20, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant