Something is not right with SafeCracker and relationships, or with the way I’m creating add/edit forms.
I created forms that create a hidden relationship for the customer (in EE 1.6x), in SAEF/Form Helper. It was accomplished by having them click on a permalink within the parent record (outside of the related entries portion)... that put the entry_id of the parent record in the hidden relationship field of the new child record, essentially: {permalink=group/addformname}.
The customer never knew they were doing this. They’d never have to deal with drop downs/drilling to find the records they needed. We’d never have to worry about screening out only their own records, as the links to the associated entries were next to the parent records (that were only their own). (I can’t take credit for this. It was a trick I learned from Mitchell at Solspace.)
Similarly, if the customer needed to edit the child records, the edit links were located within the boundaries of the parent record, again, only their own, so only their own records appeared.
I realize that I can’t have one add and edit form for this because of the entry_id—no biggie. Two forms in SOME cases, where I ALWAYS used to have to have two forms, is a situation I can live with.
In the add form, I pick up segment_3 for the relationship field (because it is a permalink from the parent record), and I dropped most of the variables from the safecracker code, especially entry_id=”{segment_3}”. I can see that the correct Entry ID is in the relationship field (because I haven’t hidden it yet, so I can see what is being placed there). I save it. I checked the database.
Relationship Table After Add:
rel_id, rel_parent_id, rel_child_id
333, 1821, 1435
After Edit:
rel_id, rel_parent_id, rel_child_id
334, 1821, 0
335, 1821, 333
Unfortunately, all of that is wrong.
After add, the initial record should have been:
333, 1435, 1821 (the parent and child record were transposed)
After edit, new entries shouldn’t have been created and the initial deleted. I don’t know if the correction of the first problem would eliminate the second.
Can you let me know if it is a problem with my method, or if there is a problem with the way Safecracker is saving relationship data?