Looks like you resolve ORM via class, not interface. That's why you get a new ORM with a clean heap ant it is trying to insert the entity because it looks new for the ORM
","upvoteCount":1,"url":"https://github.com/spiral/framework/discussions/1152#discussioncomment-10832384"}}}-
|
I normally use DI for everything, but I kept getting exceptions with duplicate keys. is this really expected behavior? class Model
{
public function __construct(
private ORM $orm,
private EntityManagerInterface $em,
)
{
}
public function method(Symbol $symbol): void
{
/** @var ShortTimeSeriesMetadata|null $metadata */
$metadata = $this->orm->getRepository(ShortTimeSeriesMetadata::class)
->findByPK($symbol->value);
if (!$metadata) {
return;
}
$metadata->setLastTry(new DateTimeImmutable());
// performs insert operation
$this->em->persist($metadata);
$this->em->run();
// performs update operation
$em = new EntityManager($this->orm);
$em->persist($metadata);
$em->run();
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Looks like you resolve ORM via class, not interface. That's why you get a new ORM with a clean heap ant it is trying to insert the entity because it looks new for the ORM |
Beta Was this translation helpful? Give feedback.
Looks like you resolve ORM via class, not interface. That's why you get a new ORM with a clean heap ant it is trying to insert the entity because it looks new for the ORM