How can I get the current entity values from loadClassMetadata?

14 views Asked by At

In my legacy database, the entities are dispatched depending on the value of an attribute. For example, the tables are called:

  • tv_rec
  • mobi_rec
  • blah_rec

and the payload I receive may be something like:

{
  "label": "The TV set",
  "domain": "TV",
  "price": 456.78
}

or

{
  "label": "One mobile phone",
  "domain": "mobi",
  "price": 123.45
}

The Entity is defined as:

// all the necessary ApiPlatform stuff
class Prod {
  private string $label;
  private float $price;
// getters and setters follow.
// Note that there is no "domain" attribute as this information is contained in the table name itself.
}

I need to chose the right table depending on the value of domain and for that, I plan to use loadClassMetadata but there is no access to the values of the entities.

How can I know which entity I'm currently acting on when I'm inside the loadClassMetadata event, in order to retrieve this value?

0

There are 0 answers