Closed nowackipawel closed 5 years ago
Have you tried debugging it in the Model's save() command yet? I can't recreate your app for test purposes, and we have tests around that which seems to save fine. If you can debug on your end and determine if something actually is a bug at the framework level then I can actually help.
There's only 2 things I can think of that might be going wrong at the framework level: Either It's not including tra_id when it converts it from an entity to an array, or the value of tra_id you're passing in evaluates as empty.
But what you have here isn't really a bug report, it's an ask for help, which should be asked on the forums. If you can confirm it's a bug with the framework, please let us know.
There was a bug in in toRawArray()
in this part:
if ($onlyChanged && ! $this->hasPropertyChanged($key, $value))
{
continue;
}
if tra_id didn't change then it wasnt avaibale in properties which were returned by toRawArray .
@lonnieezell : test what you are pointing out are not the best example for this case; they are created only for \stdClass or arrays ; there are no test which are utilizing entity toRawArray method. I hope my fix wont break that ones... but we will see. I think in PR#1772 there is less assumptions that do not have to be true. In fact, there is only one that I assumed that before inserting value of entity primaryKey was null.
Hm. Thought I had something in place that would always include the primary key. Will check that. Thanks for debugging further.
I guess, the issue is fixed with #1829.
It is grabbing the primary key when using entities and toRawArray, and this test proves it's working I believe.
This is model
Entity:
And TestCommand (spark)
and its output:
I am wondering why save is trying to produce INSERT instead of UPDATE .. WHERE tra_id = 121 ?