Noob Sanity Check Conceptual Question

Noob Sanity Check Conceptual Question

TPCSLtdTPCSLtd Posts: 4Questions: 1Answers: 0

Apologies if this is way off, but can I sanity check my thinking?

If I have two tables - tblAddress and tblAddressContact. tblAddress being an address list, and tblAddressContact linked with a foreign key, so we can have a number of contacts at a single address.

When creating a new address, I need to add at least one contact. So in my mind, the Create form needs to include the contact details and create a new (linked) record in both tables.

When editing, we only want to edit the address fields, as there could be more than one contact. The editing interface would follow Allans blog post - https://datatables.net/blog/2016-03-25

I dont think I can use Join...as I only want a join on a create.

So conceptually, I'm thinking:

  1. Client side, catch the 'initCreate' and 'initEdit' events and show() and hide() the fields for the contact data (e.g. the tblAdressContact record)
  2. Server side, catch the 'postCreate' event and grab newly inserted rowid and create our new contact row.

Firstly is this a sensible approach, I've got that 'you've missed something feeling'? I have got some code along these lines nearly working...

If I am heading down the right track, how to I handle the Contact fields? Can I just grab them either from $_POST or $values array provided postCreate?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin
    Answer ✓

    Just to check my understanding - on create you want to insert into two tables, but on edit you are modifying on one table only. Is that correct?

    If so, you might want to consider simply have two Editor instances, one for create and one for edit, with their fields specified as required. Also, if Editor doesn't receive information for a field form the client-side it doesn't attempt to write it, so it might actually be possible to do this with a single instance, but two is probably easier.

    Allan

  • TPCSLtdTPCSLtd Posts: 4Questions: 1Answers: 0

    Hi Allan

    Just to check my understanding - on create you want to insert into two tables, but on edit you are modifying on one table only. Is that correct?

    Spot on!

    If so, you might want to consider simply have two Editor instances, one for create and one for edit, with their fields specified as required. Also, if Editor doesn't receive information for a field form the client-side it doesn't attempt to write it, so it might actually be possible to do this with a single instance, but two is probably easier.

    Thanks. Told you I was missing the easy answer :) I have managed with a single instance, but I had a feeling it wasn't the best way

This discussion has been closed.