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

Error when trying to get all meta for object #93

Open
peirix opened this issue Jan 12, 2023 · 5 comments
Open

Error when trying to get all meta for object #93

peirix opened this issue Jan 12, 2023 · 5 comments

Comments

@peirix
Copy link

peirix commented Jan 12, 2023

I get an error when trying to fetch all meta belonging to an object:

Plank\Metable\DataType\Registry::getHandlerForType(): Argument #1 ($type) must be of type string, null given, called in /var/www/html/vendor/plank/laravel-metable/src/Meta.php on line 76

I have the full error stack here: https://flareapp.io/share/oPRq3OAm#F63

Running:

php: 8.1.11
laravel: 9.37.0
metable: 5.3.0
@frasmage
Copy link
Collaborator

It looks like your Order record has one or more Meta entries where the type field is undefined/null. You might want to check what meta rows you have in the database for that entity. Did you instantiate any of the meta values directly (as opposed to setMeta() which will always set the type field) or perform any manual data manipulations on the database? What is the value field of that meta entry?

@peirix
Copy link
Author

peirix commented Jan 12, 2023

Hi. We're using syncMeta() to set the fields from a users meta to the orders meta:

$order->syncMeta(array_merge(
    $request->user()->account->only(['invoice_email']),
    $request->user()->account->getAllMeta()->only([
        'invoice_name',
        'invoice_org',
        'invoice_address',
        'invoice_zip',
        'invoice_city',

        'shipping_same_as_invoice',
        'shipping_name',
        'shipping_address',
        'shipping_zip',
        'shipping_city',
    ])->toArray()
));

And the database looks to be correct:
image

I see now that there are some fields missing there (the shipping fields) for some reason. I'll have to look into why, but would that cause an issue that they're not there? It should just return all available meta fields anyway, right?

@frasmage
Copy link
Collaborator

AFK, but is it possible that the only() method is returning empty keys for ones that don't exist? Probably some tuning that could be done to the package to better handle that scenario, but you might be able to work around it by using array_filter before syncing

@peirix
Copy link
Author

peirix commented Jan 12, 2023

But still not sure why I'm getting an error on empty types based on the information that is in the database now?

@peirix
Copy link
Author

peirix commented Jan 12, 2023

I tried manually adding the missing fields to the meta table, but that didn't change anything. I see that some of my orders don't give this error message, and those orders have all the fields set in the meta table. So it seems to be related to that somehow.

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

2 participants