XF 2.1 Creating sub-entities of currently creating entity

CMTV

Well-known member
Hi!

In short, I have Criterion and Param entity classes.

The thing is that I want to allow admins to add Param entities during the creation of criterion (ajax adding). But insta-saving params data right to database while creating the criterion is not a good idea because the user can simply close the browser tab. Result: params are not connected to criterion because there is no criterion.

The only way I see is to force user to create Criterion frist and only after that (after reloading the page) show "Params" tab where you can add params... But this is horribly not obvious and inconvenient for users...

So, how to dynamically add "child" entities, but not save them in db until the "parent" entity creation finished?
 
Last edited:
send/store them all at the same time
Well, in this case I have to store param entities till criterion saving process. I don't know if there any simple way of doing this...

Of course, I can create additional inputs when adding params and them loop through them and create param entities when saving criterion but this is kind of messy...
 
Guess I'd take a look at how attachments are handled in that case. That's the only case I remember XenForo creating child entities before the parent.
 
If I absolutely had to create child entities first, I would just have a column on the children that tracks whether or not they are associated with a parent, paired with cron that periodically purges any unassociated ones. You can have them default to unassociated and then mark them associated when the parent is created/saved. This is basically how attachments are handled.
 
Back
Top Bottom