0 votes

This setting is throwing a fatal error because there's no such thing as a bigInteger cast in a laravel model. We are being forced to delete every $keyType property manually on every export. This isn't ideal. Am I doing something wrong in Skipper?

in Solved by (160 points)
recategorized by

Hello, can you please be more specific about this issue?

bigInteger is default Laravel datatype: https://laravel.com/docs/8.x/migrations#column-method-bigInteger

Also, I don't understand what do you mean by $keyType. Is this some kind of your own property? Can you please create a minimal test case model where is this bug reproducible?

Thanks for the quick response - the issue is on the Abstract models being created.

The model is using the protected $keyType = 'bigInteger'; but there is not a cast with the same name. This is causing a fatal error while creating models. Why not just use the integer cast on this column?

It mapped the column correctly in the casts array but the generated model says to use that bigInteger key type which is the issue.

protected $keyType = 'bigInteger'; is generated because the datatype of your primary key is bigInteger,

KeyType is defined in the documentation here: https://laravel.com/docs/8.x/eloquent#primary-keys

It would really help if you can provide a minimal test case project with a detailed description where/what is wrong.

The problem is there is no default laravel model cast called bigInteger.

For instance if you were to simply just fire up any model that was created with Skipper, and call the $model->getKey() method, you would get this error. This is happening because of the casting of the primary key - not having a valid cast.

Call to undefined cast [bigInteger] on column [id] in model XXXXX

--- in Database/Eloquent/Concerns/HasAttributes.php:1196

Oh, ok, this is probably our bad. We interpreted wrongly this paragraph in the doc:

If your model's primary key is not an integer, you should define a protected $keyType property on your model. This property should have a value of string:

Now, if I understand correctly, $keyType should hold the same value as in the $casts variable?

protected $casts = [
    'id' => 'integer',
    'created_at' => 'datetime',
    'updated_at' => 'datetime',
    'name' => 'string'

So when bigInteger is cast as "integer", the $keyType should be integer too (but because it's not different than integer, the $keyType will not be exported at all)?

Sorry for these questions, we've not experienced Laravel devs and any help from the community is welcomed.

100% correct :) no need for the key type property to be changed unless it's a string - like using UUID's etc.

I've only been using Skipper for a day now - and this came up instantly. I'll report any other issues if I see them during the dev cycle.

Thanks for responding so quickly.

Thanks for confirming. This will be a simple fix. i will let you know when the new beta will be ready.

Also, please feel free to let me know any other issues or ideas on how to improve our application.

It's fixed in the latest beta.

Please download it here https://www.skipper18.com/support/402/downloads-skipper-beta

1 Answer

0 votes

It's fixed in the latest beta.

Please download it here https://www.skipper18.com/support/402/downloads-skipper-beta

by Skipper developer (141k points)