dedoc/scramble

integer or null issue in mongodb

Closed this issue · 3 comments

Laravel 11, mongodb (no real column types, we don't create schema migrations for mongodb)
Slightly more difficult to show example but I'm doing my best:

/**
 * @mixin Booking
 */
class BookingResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
           'type' => $this->type
        ];  
     }
 }

Booking:

/**
* @property int $type
*/
class Booking extends Model
{
   use HasFactory;

   protected $casts = [
       'type' => 'integer',
   ];
}

Actual:

image

Expected:
Only integer, no "or null"

Is there any way to improve this for non sql database?
Referrence:
https://github.com/mongodb/laravel-mongodb

P.S. I can do like this:
'type' => (int) $this->type
But this would need a lot of changing in many resource files and for many attributes. not only int.

@benascbr for these issues with MongoDB I would appreciate your investigation and PR. Feel free to dump stuff in ModelInfo and ModelExtension classes to figure out why this is happening.

@romalytvynenko thank you I will try.

However question: in case get type from database fail, and scramble defaults to @Property or $casts. And both @Property and @casts indicate that value is integer.(no indication of null) Maybe scramble should write integer instead of "integer or null"

thoughts?

@benascbr Scramble defaults to casts only. I really have no idea why null is there.

I agree it should be int only.