tags:

views:

34

answers:

1

I'm not sure how to explain this so I am going to try do it as clearly as I can.

We have a case logging web app. When one adds a case ticket, one can add contacts and attachments to that ticket.

I am trying to find a way for the visitor to fill in the case ticket information, add n contacts and then n attacheents before having to push save.

The attachments and contacts are linked to the ticket table and so will need to know the tickets Id in order to insert the correct reference Id.

What are the different solutions that can be implemented?

A: 

One option is to introduce linking tables; so instead of:

                               contact
ticket                         -------
------                         PK id
PK id <----------------------  FK ticketid

you could have:

ticket       ticket_contact
------       --------------    contact
PK id <----- FK ticketid       -------
             FK contactid ---> PK id

Now you can save contact records before ticket (or ticket first) - and just add in the linking records when you have both. This also allows you to re-use contact in scenarios unrelated to ticket.

Another (simpler) option is just to make the FK nullable... that might be OK I guess.

Marc Gravell