-
Notifications
You must be signed in to change notification settings - Fork 28
Respect model casting while querying a model #856
Comments
A related change was applied and was reverted in: laravel/framework#15018 |
Casting the attributes doesn't solve the issue for JSON values. At least on MySQL, you can't query a JSON column by using |
I am having problems with this in laravel/framework v6.2.0. |
@themsaid, it seems to me that the changes proposed in laravel/framework#30958 PR will allow this to be implemented in custom castes. |
@andrey-helldar that'd be great! it's horrible that the original code was written in a way that broke this feature in the first place. thanks for fixing it! |
@andrey-helldar Your PR seems to handle the casting of values, but it's not clear how you modify the behavior of firstOrCreate. Could you explain further how that PR solves this issue? |
@sisve, the developer himself will be able to create custom types of objects processed both when they are received from the database and when they are written (create, update). |
@andrey-helldar I'm not sure you can properly assume that. Does your PR modify how Laravel filters on values? If I were to |
@sisve, I think not, such a method will not work because Cast is an extension of Eloquent while the where method is called from QueryBuilder, and this functionality does not affect it. |
Original Issue: laravel/framework#12238
This might be related to #5578, but if I have a model that uses
$casts
, then thefirstOrCreate()
always creates a new instance. For example:The text was updated successfully, but these errors were encountered: