Table with self relationship

Asked

Viewed 697 times

0

Good morning.

I have a table that uses auto-relationship, it turns out that not all names entered have parent, but I can not create a name with null parent, there is not be the first that was created, as in the example below.

Example:

id                                         name               pai

02016356-ED97-439B-8E78-4200547BD5AC      Presidente          null
239A0DB8-4282-45E5-B5AE-5A2702576E49      Diretoria Geral    02016356-ED97-439B-8E78-4200547BD5AC

Form code

<form:select path="parent.id">
    <form:options items="${parents}" itemValue="id" itemLabel="name" />
</form:select>
  • The column pai is set as default value NULL?

  • I think my failure is time to register, because I have an input field where I will put the name and just below I have a combo to choose the father, however, as this value is coming from the bank it does not have a blank field to register null the father, then the option already comes with an initial value.

  • Your column is UNIQUE? You need this?

  • The column is not Unique.

  • And because he only accepts one NULL? If you don’t demand oneness, you should accept as many as you want.

  • it accepts other values that do not accept null, but this is what I want, that accepts null, I can not put via system, only directly in the bank ...

  • So maybe the problem is in the application, because if you don’t have the restriction of UNIQUE you have to accept, and in fact you say you accept several NULL. The problem doesn’t seem to be in the database. Either you explain it better, or you change the question to focus on the application or I don’t know how to help.

  • You can place the DDL (table creation setting) in the body of your question?

  • Post the select mount code to select the parent. I think the problem is in the view and not in the bank. What you want is to allow registration without a father, that’s it?

  • Lucas, that’s right, the problem is in the view. <form:select path="Parent.id"> <form:options items="${parents}" itemValue="id" itemLabel="name" /> </form:select>

  • What language are you using?

  • Java with Spring MVC.

Show 7 more comments
No answers

Browser other questions tagged

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