Closed bohdan-vorona closed 1 year ago
Reviewing today. I agree that the address makes it tricky.
I will create an issue to move the address to the order
table which is where it should be IMHO. I'll create the issue and as a team can discuss.
I found a strange issue when an address is updated but an item is missing.
Let me know if this picture makes sense. Other tests appear to work fine. I think it could be related to some orders not having items in my test DB?
@cgsmith
I found a strange issue when an address is updated but an item is missing.
Thanks, I will try to reproduce the issue and fix it.
I found a strange issue when an address is updated but an item is missing.
Let me know if this picture makes sense. Other tests appear to work fine. I think it could be related to some orders not having items in my test DB?
@cgsmith It seems that you have one Address model for several Order models. I thought we have a 1-to-1 relation, isn't it? Can you please recheck this fact on your side?
Yes you're correct. I remember now. It used to be one to many but is now one to one. This is technical debt and the address should be 1 to 1.
@cgsmith Thanks. I will add order by ID DESC
anyway.
@cgsmith Thanks. I will add
order by ID DESC
anyway.
Good workaround. Please note it as a comment on why it is id desc
Please note it as a comment on why it is
id desc
@cgsmith
Pardon maybe I didn't understand you correctly) Let's clarify)
So, the reason that there was an Address for several different Orders. During updating the Address, I'm searching for a specific Order by the field address_id
. At the moment I use this code:
$order = Order::find()
->where(['address_id' => $this->owner->id])
->orderBy(['id' => SORT_DESC])
->one();
It means that I consider we have a 1-to-1 relation.
A) If we're going to use a 1-to-1, it would be better to keep the current code with one()
.
B) Or, I can replace one()
with all()
but in this case, all orders with this address_id
will have "Address is changed".
I just meant to have a comment in the code why we are doing the id => desc
- that way in the future we don't remove it by accident.
Address for several different Orders
@cgsmith Got it now) Added)
common\models\events
.Events:
Traits:
Enable/Disable:
Added events:
ONE IMPORTANT MOMENT:
I started implementing the logic via one event like one "Order is created" with data of Address and Items together. But then I had to split it into:
Why:
address_id
.OrderViewed
is used in the controllerOrderController
->actionView
.