Is there a way to learn something like this in the doctrine:
class Entity { private $relatedEntityId; private $relatedEntity; }
What I want to do, I am doing something like this:
call Entity :: setRelatedEntityId ($ someId) and save the object, and the entity returns the associated object by calling Entity :: getRelatedEntity ().
A related object is selected from a table that will be strictly limited and will never dynamically grow at run time, so there are a finite number of identifiers for related objects.
When creating a new Entity, I would like to set the identifier of the related object, but without the need to retrieve the entire associated object from the database.
As far as I can verify this, this will not work, because if I set the related EntityId but not the related element, Doctrine automatically sets the related_entity_id column to null, because in principle the relationship is not established.
I also tried to do something like this:
remove the relatedEntityId property and use
Entity::setRelatedEntity(new RelatedEntity($relEntId))
the constructor of the RelatedEntity function will set id, but not other values. I donโt want the persistence of a bound Entity (these values โโare already set in the database for the given $ relEntId), but this time Doctrine signals a flash error because it has an uncertified object.
Basically, I want to create a relationship, not knowing anyhing, but the identifier of the associated object. If there is another way, this can be done, please share.
Thanks in advance
EDIT:
I found a workaround. Since RelatedEntities will be a limited set of immutable objects, I did the following:
- use entityManager to find all related items;
- enter a list to the object that will create new objects
- when creating a new object, select one of the events associated with it from the list as an element associated with it
I will leave the question open for a day or two, just in case someone comes up with something better.