Is it possible to insert new options into joined tables?

Is it possible to insert new options into joined tables?

Manoel WallerManoel Waller Posts: 7Questions: 2Answers: 0

Hey

I recently started to work with editor because i need it for a school project where I have to make a website that shows joined tables from a database.
Tables: Students [id, name_id, gender_id, class_id]
Name [id, name]
Gender [id, gender]
Class [id, class]

I got almost everything set up and workin very well. The table Students is showed on the website and shows the names, genders and classes according to the foreign keys stored in it. I can add, delete and edit students. However when i want to add/edit a user i can only select names, genders and classes which are already stored in the tables (Name, Gender, Class).
So now to my actual question: is there a way to dynamically add a new name to the select and automatically insert it into the name table?

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Not really. It is actually possible with a plug-in such as Select2 which will let you create new values via its options (see the Select2 documentation) and that could be written to the joined table. But it is limited since it can only add that one extra property. That might be okay in this case, but that's relatively unusual.

    Typically I'd suggest just having a second table for the names.

    Actually, more generally - why is the name in a separate table? Can the same name really be assigned to multiple different students? Even if students did happen to share the same name, if you had to change the name for one, you typically wouldn't want to change the name for the other.

    Allan

  • Manoel WallerManoel Waller Posts: 7Questions: 2Answers: 0

    Hi
    Thanks for the answer
    I'll try the select2 plug-in

This discussion has been closed.