Skip to content

[Bug]: Getting ORM:class from $app creates new instance #752

@mm-sol

Description

@mm-sol

Describe the bug

When getting ORM:class from laravel $app container laravel creates new instance. It leads to hard to find&fix "duplicate key value violation" on entity when updating (because entity manager has different orm).
It's understandable that it shouldn't happen as everyone should use ORMInterface class, but mistakes happens.

Is this a regression?

Dunno

To Reproduce

  1. spl_object_hash($app->get(ORM::class))
  2. spl_object_hash($app->get(ORMInterface::class))
  3. compare
  4. hash mismatch

Expected behaviour

hash matches

Media prove

No response

Your environment

No response

Additional context

Fix:

Add code below to src/Bridge/Laravel/Providers/Registrators/RegisterORM.php:

$this->app->singleton(ORM::class, function ($app) { return $app->get(ORMInterface::class); });

Sorry for not making pull request with this, no time, deep in deadlines.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions