I need to insert an entity which has associations.
If I already have the FK’s of the associated entities, is there a way to insert the primary entity into the db with just the FK’s populated?
Or do I always have to
- retrieve the associated entities via the FK’s,
- populate the primary entity’s properties referring to the assocations,
- and then invoke the persist method.
You want a reference proxy
Let’s say I have Posts and Tags. A Post hasMany Tags. I get a bunch of tags from the user, who checked a bunch of checkboxes.
The following would add tags to an existing post, without fetching each tag entity first. It does this by using reference proxies, generated by
EntityManager::getReference():