I have an object that hasn’t been created yet (so it has no ID), but the user is in the process of filling out fields to create it. For one of the fields, they create an attribute for this object, but that attribute requires the object’s ID.
That’s where the issue is — since the object hasn’t actually been created yet (the user is in the process of filling out fields to create it), it doesn’t have an ID. When you’re editing the object and thus have the object’s ID, creating attributes is no problem.
Here is the relationship:
OBJECT (name, id)
^ ATTRIBUTE (name, object_id, id)
How do you deal with situations like this? I was considering adding an “is_temporary” field to the object so that it can get an ID right off the bat, but surely there is a better way?
Great question, actually. You have two options:
The latter is far easier to implement, but requires you to include is_temporary=’false’ everywhere else you access the objects, and also mucks up your ID sequences when people cancel.
The choice depends on the difficulty of the ATTRIBUTE creation code. If it’s hard to make it persist in the form until the object is created (without an ID), then choose the latter option. Otherwise, choose the former.