What is the cardinality between a request and the services included in it?

Asked

Viewed 1,047 times

14

I have the class Solicitacao and the class Servicos. After insertion in the database I intend to recover in a query all the services associated with that request.

For example, on a screen I insert the request and various services. When the time comes to make the query I want to bring the request and as soon as click a button appear a Dialog with all services of this request.

That relationship would be 1-N or N-N?

My diagram: UML

  • if your service can only have one request then it would be 1-N ( one request for multiple services).

  • Like, is this service only good for this request at the time of this registration? For example if I start a second registration and use the same service registered in the first would still be 1-n?

1 answer

11


Depends on what these services are.

If the services are specific to this request, that is, they are line items that the request should have, then it is 1-N. For each request you have multiple services. But a service can only be on one request.

But if the services are generic and are registered in the request directly, then you have a relationship N-M (N-N would mean that the relationship should have a number of symmetrical items). You have a request that is composed of multiple services. Each service can be in as many requests as needed.

So the description is the second way. But in general this is design bad. It would be right to have a table of Itens de solicitação in relation to 1-N. And each item have a relationship with Serviços of N-1. That is, each request item has a related service, but each service can be in any number of request items.

With the question editing and placement of the diagram, it seems that the table Servico works as a request item, so it would be 1-N. The name gives wrong indication of what the table is. The column codigo also weird. Is the code of this service? And how links with the request? If this is the request code, it has a link, but then it would have to be 1-1 since it would not be possible to have a primary key otherwise.

Modeling depends a lot on the specific situation. You have some basic ideas to follow but without fully understanding the problem it is difficult to say anything. And from what I see, one of the biggest difficulties for developers is completely understanding the problem. When escapes a detail and models wrong will pay up there. I still miss a lot, even with more than 35 years of experience. But I make a great effort to get it right because this is more important than most of the other skills in our work. Understanding the wrong problem will certainly produce the wrong solution and it is not always obvious until it is too late and it is much more difficult to fix the problem.

One more detail: you are using double for monetary values, this is terrible, see What is the correct way to use the float, double and decimal types?. The use of long for the codes does not seem appropriate to me.

  • I understood, in my case I have a registration screen where I add the request along with the service this option to create the table Itens de solicitação is valid?

  • 1

    Read my issue, see if you can understand the problems you’re facing. Since you don’t master the nomenclatures, it is difficult to understand what you want. Until you master these things, you will have difficulty modeling. But I think you should have this table that I said and the service be a separate entity. If you want to make the service just an information thrown in the request, then you don’t need this other table but would still have problems in the way you mounted it.

  • The code is auto increment, but I think I already understood more or less. It is my first modeling after some time, I have to train rsrs

  • @bigown, just taking a doubt recommends String, int or integer for codes?

  • I put double in the values because I did not find Bigdecimal in Astah, and what I use for the code?

  • 1

    @Wellingtonavelino there is another question :D If it works like an ID I go from int in almost every situation. If it is a user code, it depends on how it can be formed. In many cases I would go from string but this type of code has fallen into disuse in modern applications, I would avoid. Today codes tend to be irrelevant in many situations. If the number control has to be independent of the DB ID, then you will have some routine that will generate it according to the need. It is better string or int? I don’t know, it depends on the situation, but I’d say you have a better chance of being string.

  • @bigown, hahaha, awakened more doubts, I will generate a more specific question, thanks for the comment!

  • The biggest problem is that I am u sole developer of the kk company and barely finished college. I will be doing the diagrams in the simplest way to start so as I gain knowledge I can improve these diagrams. Thanks for helping.

  • And ask here if you have specific and well defined problems.

Show 4 more comments

Browser other questions tagged

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