laravel-dynamodb icon indicating copy to clipboard operation
laravel-dynamodb copied to clipboard

$cast

Open baopham opened this issue 7 years ago • 8 comments

Double check plz

baopham avatar Oct 28 '18 12:10 baopham

$casts don't work the way the user expected it to in #166 $casts only are suppose to apply while accessing a value on the model, not before storing them in the database. See this entry and example in the doc.

As there is nothing to change i suggest closing this issue

Tamrael avatar Nov 09 '18 10:11 Tamrael

No, this is there for me to ensure $cast is supported. It isn't with the aim to cater for that issue scenario. The user mentioned $cast and it made me realize that I have not tested this feature.

baopham avatar Nov 09 '18 10:11 baopham

sure, got that but as $casts is non database related and is handled in Concerns\HasAttributes and the DynamoDbModel extends the Eloquent Model which uses the HasAttributes Concern which only acts on the models attributes when accessed directly and you don't overwrite any of this, I thought you might not want to wast your time chasing ghosts. It's Eloquent default behavior.

Keep up the great work <3

Tamrael avatar Nov 09 '18 10:11 Tamrael

Haha thanks for that. I had concern about letting it roam free without proper testing. I just need to double check if there are any formats that would not work, then I can document it perhaps. Thanks for helping me groom thru the backlog. Appreciate it truly.

baopham avatar Nov 09 '18 10:11 baopham

Is there a better way of doing what I've implemented in this commit, and if you wouldn't mind, is there any edge cases I may have missed? (constraints?) cbf6bd6c27211750f37324d4a20d6049011b2f2c

My use case is storing an unsigned 64 bit integer to the database as a Number, but as PHP does not support unsigned integers, I have to store this as a string when referencing to it. So, I use this code (which is very hacky imo) to cast before making the DynamoDB queries. I also need this to store unix timestamps as Numbers, which the library does not seem to do.

Many thanks.

adam-the avatar Apr 15 '20 10:04 adam-the

On the timestamp problem, how are you generating the timestamp? We use $model->createdAt = now()->timestamp and it stores it as a Number.

zoe-edwards avatar Apr 16 '20 14:04 zoe-edwards

I'm using $dateFormat = 'U' and the serializeDate function in the model then let Laravel handle the attributes for me. No need to set them manually. I guess it just serializes as a string like that?

adam-the avatar Apr 16 '20 19:04 adam-the

Ahh that’s annoying. Weird that’s how Laravel handles that, I guess dates are normally strings if not an object. I wonder how deep that goes, possibly it’s changeable.

zoe-edwards avatar Apr 17 '20 08:04 zoe-edwards