Modeling for shared address table

Asked

Viewed 1,598 times

3

I have 3 entities: Ponto, Solicitante and Serviço. Each one has its own address, but it is possible that the 3 have the same address.

If an entity changes its address, it shall not change the address of other entities, even if they have the same address.

For example: A requester has a service for their current address. When the requester changes address, the service will still be related to the old address.

It is also possible that several Services have the same address. And if the address of a service is changed, this change should not affect the address of the others.

Given the current data model (below), what would be the best strategy to avoid duplicated data ensuring that no changes will affect the other?

DER

  • 1

    What is the point? Is there any reason for the service to have an address, not just have the requester? It seems to me that deep down the addresses are not the same, they can be coincidentally the same, which is not enough for the use. How you determine how to take advantage of the same address?

  • @bigown The reason why the 'Service' has one address and the 'Requester' another, is that the address of the service, will not always be equal to the address of the requester. Point is a place, a piece of street, which is identified by the address. This has no relation to the service or requester.

  • About the use, I haven’t decided yet how to do. I just find it strange to keep several equal records in the address table. I don’t know if I change the modeling to another, or if I create some algorithm to control it.

1 answer

2


I don’t know how you’re gonna repurpose the existing address. My experience is that this works better on paper than in practice, but it was just a supplementary comment.

What you can do is use immutability. So register an address that will have one id somehow it can be used by other entities. So far I think it’s ok. When you need to change from one of these entities, the application will not write to the existing line where the data was read, it will create a new line with the changed data.

Then think what happens if you have to change the address and the change has to be applied to everyone who points to this address. How do I fix this? I have no idea. Will you let the user decide? It doesn’t usually work, they always get it wrong. What if it has to change at some points but not at others? Confusing is not?

Then it is likely to start to proliferate new lines where they should not. Of course it may be that you need it. On the other hand, if an address is linked to a service, then it should never be changed. This usually occurs on a bill by law. If by chance the address is wrong you have to use a correction of the address, you can not just go there and change the existing one, it is immutable.

In this case it might be interesting:

  • The address is registered for the first time in the applicant;
  • the service is created and uses the same address (id) that is in the applicant’s register;
  • when the requester changes the address, does the immutable scheme I talked about and creates a new address for it (changes the note on the requester’s foreign key), but does not affect others who are using that address;
  • the service is prohibited from changing the address. This means that if there is change it needs to be a rectification or the service is actually another (in some case it can be relaxed).

I did not understand the function of the point there. But if it has no relationship with others, it does not matter, I just found it strange to be in the description of the question.

Readings that may help (or complicate :) ):

  • Yes, @bigown you’re right about the reuse of the address working well on paper and not in practice. I’ve come to that conclusion. This solution of including a new address for each change would be a little strange, because imagine that an address could be without connection with any entity. I will use each address inclusion being a new record in the address table, no matter if there is already an equal. Because the address is unique to each one anyway. So, if you change, you will only change the correct address.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.