How to understand entities, save, hasChanged |
(06-07-2024, 06:51 PM)kenjis Wrote: Read the error message carefully. Thank you Kenjis. It is my lack of understanding of entities. I thought that if QgisResort was empty and I fill it, it will treat it as new if I save it. Do I need to fill $QgisResort and then save? How should this work? Thank you again.
It seems you misunderstand something.
PHP Code: $QgisResort = $this->QgisSkiResortModel->find($new_fill['id']); The Model::find() method returns null if the entity is not found.
(06-07-2024, 07:39 PM)kenjis Wrote: It seems you misunderstand something. I am trying to: - insert new data if the entity doesn't exist - update existing data if the entity exists I am confused how to use find(), fill() save() hasChanged() to accomplish above. Very sorry but what is the basis logic to accomplish this? I understand find(). It will be null if not found and means I should create a new entity to save. After that do I create a new entity and fill() to it and then save()? If find() finds something, do I fill that entity object with fill() and check thereafter if hasChanged()? and then if hasChanged() i save() it? Thank you.
Thank you Kenjis.
It now works. Something like this right? It now saves on new data, updates and doesnt do anthing if the record is not changed. PHP Code: foreach ($aa_winter_sports_points->features as $aa_winter_sports_point ){ |
Welcome Guest, Not a member yet? Register Sign In |