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

$cast #167

Open
baopham opened this issue Oct 28, 2018 · 8 comments
Open

$cast #167

baopham opened this issue Oct 28, 2018 · 8 comments
Labels

Comments

@baopham
Copy link
Owner

baopham commented Oct 28, 2018

Double check plz

@baopham baopham changed the title $cast $cast Oct 28, 2018
@Tamrael
Copy link

Tamrael commented Nov 9, 2018

$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

@baopham
Copy link
Owner Author

baopham commented Nov 9, 2018

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.

@Tamrael
Copy link

Tamrael commented Nov 9, 2018

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

@baopham
Copy link
Owner Author

baopham commented Nov 9, 2018

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.

@adam-the
Copy link

adam-the commented Apr 15, 2020

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?)
cbf6bd6

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.

@zoe-edwards
Copy link
Collaborator

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

@adam-the
Copy link

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?

@zoe-edwards
Copy link
Collaborator

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.

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

No branches or pull requests

4 participants