This topic is locked

many-to-many revisted

3/14/2011 10:48:24 AM
PHPRunner Tips and Tricks
P
pvdemael author

I have another question on many-to-many relationships.

I have implemented the solution described here.

This works like a charm. But now I want to be able to add data to the linking table from both tables.

This is the situation:
I have 3 tables
Table event with fields

  • event_id
  • event_name
  • event_startdate


Table volunteer with fields

  • vol_id
  • vol_name
  • vol_address


Table event_vol as link table with fields

  • event_id
  • vol_id


I've setup a master-detail relationship with event as master and event_vol as detail.

To be able to inline add a volunteer from the event list, I've setup the event_vol table list to show the volunteer name and address and unset some variables in the BeforeAdd event.

This works perfectly.
I now want to do the reverse too, adding an event to a volunteer. I thought this would work by creating a view of the event_vol table and setup the list to show the event name and starting date.

I just had to change the BeforeAdd event to add data to the event_vol table, because you cannot add to a view. However, in order to be successfull, the BeforeAdd event has to return a true.

This will trigger an error because you cannot add to a view and returning a false will trigger the error and show the error message.
In short: I want to add data to the event_vol table from both the event and volunteer tables by creating two master-detail relationships with the event_vol table. I want the event_vol table to show different columns, depending on the master table. Using a view does not work because of the limitation to add to a view.
I think there is a simple way to implement this, but I missed it.
Thx for your tips!