You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Model] Upsert problem with data validation, allowed fields, dates defined #7286
Which operating systems have you tested for this bug?
Windows, Linux
Which server did you use?
apache
Database
MySQL (ver. 8.0.28)
What happened?
Upsert does not work correctly with the model.
Allowed fields, validation rules, dates (created_at, updated_at) are defined within the model, this does not apply to the query.
The model should throw validation errors first!
Important
The Model does not provide a perfect interface to the Query Builder. The Model and the Query Builder are separate classes with different purposes. They should not be expected to return the same data.
If the Query Builder returns a result, it is returned as is. In that case, the result may be different from the one returned by the model’s method and may not be what was expected. The model’s events are not triggered.
changed the title [-]Bug: Upsert problem with data validation, allowed fields, dates defined within the model.[/-][+]Bug: [Model] Upsert problem with data validation, allowed fields, dates defined[/+]on Feb 20, 2023
By the way, why do you need to use upsert() in the Model?
When we need to save something, we use insert(), update() or save() (model methods). When we want to use insert() or update() (upsert()), we don't have that method in the model. I understand that query builder and model are different classes and give different queries (example soft delete will not add in the query builder, but model will add, which is fine).
I think it is necessary to have an upsert() in the model.
Otherwise, what is the purpose of having it only in the query builder?
Output for the errors() method
returns null, should be a validation error for the item_id field
$model->errors(); // returns `null`, should be a validation error for the item_id field
Output for the method getQuery() , col1 is not in allowed files and I get a database error for an unknown column, and item_id is string, must be natural no zero.
Otherwise, what is the purpose of having it only in the query builder?
No, no. It was just added in Query Builder.
If you want to UPSERT, now you can use it with Query Builder.
As you know, not all Query Builder methods work with the Model.
If you really think the upsert() should work with the Model,
please make a feature request or send us a PR.
This is not a bug, just the current Model does not support the method.
changed the title [-]Bug: [Model] Upsert problem with data validation, allowed fields, dates defined[/-][+][Model] Upsert problem with data validation, allowed fields, dates defined[/+]on Feb 21, 2023
Activity
kenjis commentedon Feb 20, 2023
What are the current outputs?
kenjis commentedon Feb 20, 2023
This is not a bug.
The model does not have the
upsert()method. So it is a Query Builder method.kenjis commentedon Feb 20, 2023
By the way, why do you need to use
upsert()in the Model?[-]Bug: Upsert problem with data validation, allowed fields, dates defined within the model.[/-][+]Bug: [Model] Upsert problem with data validation, allowed fields, dates defined[/+]maniaba commentedon Feb 21, 2023
When we need to save something, we use
insert(),update()orsave()(model methods). When we want to useinsert()orupdate()(upsert()), we don't have that method in the model. I understand that query builder and model are different classes and give different queries (example soft delete will not add in the query builder, but model will add, which is fine).I think it is necessary to have an
upsert()in the model.Otherwise, what is the purpose of having it only in the query builder?
maniaba commentedon Feb 21, 2023
Output for the
errors()methodreturns
null, should be a validation error for the item_id fieldOutput for the method
getQuery(),col1is not in allowed files and I get a database error for an unknown column, anditem_idis string, must be natural no zero.kenjis commentedon Feb 21, 2023
No, no. It was just added in Query Builder.
If you want to UPSERT, now you can use it with Query Builder.
As you know, not all Query Builder methods work with the Model.
If you really think the
upsert()should work with the Model,please make a feature request or send us a PR.
This is not a bug, just the current Model does not support the method.
[-]Bug: [Model] Upsert problem with data validation, allowed fields, dates defined[/-][+][Model] Upsert problem with data validation, allowed fields, dates defined[/+]