I have a handler which uses the same Entity
for two different kind of queries:
/**
* @ORM\Entity
* @ORM\Table(name="app_iso50k1.meter", schema="app_iso50k1")
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="mettype", type="string")
* @ORM\DiscriminatorMap({"phy" = "PhyMeter"})
*/
abstract class Meter
{
const TYPE_PHYSICAL = 'PHY';
const TYPE_VIRTUAL = 'VIR';
const TYPE_LOGICAL = 'LOG';
/**
* @ORM\Column(type="string")
* @ORM\Id
*/
protected $id;
<methods>
}
/**
* @ORM\Entity
* @ORM\Entity(repositoryClass="PhyMeterRepository")
* @HasLifecycleCallbacks
*/
class PhyMeter extends Meter
{
/**
* @ORM\Column(type="integer", nullable=false)
*/
protected $idInstrum;
/**
* @ORM\Column(type="integer", nullable=false)
*/
protected $idDevice;
/**
* @ORM\Column(type="integer")
*/
protected $instrumType;
...<methods>
}
The first handler's method is performed on a legacy DB table and it would need to map all the fields annotated with @ORM\Column
(id
, idInstrum
, idDevice
, instrumType
). To do that, I use a primitive query and I map the data by means of a ResultSetMapping
$rsm = new ResultSetMapping;
$rsm->addEntityResult('Belka\Iso50k1Bundle\Entity\PhyMeter', 'mt');
$rsm->addFieldResult('mt', 'id', 'id');
...
and it works like a charm. The problem is on the the other handler's methods which need to persist data on app.meter
table: what I really would like to persist are a small part of the properties (i.e. just the id
, idInstrum
but not instrumType
so as not to have that column in my new table's schema.
I was thinking about using StaticPHPDriver
but I'm not sure if it is the right way: what I really would like is manually adding/removing some ORM mapping according to my needs (i.e. different handler's functions)
Is that possible? I could remove the mappings (@ORM\column
annotation) I don't need to persist, but that way I cannot map the extra properties by using ResultSetMapping
, unless I can add it programmatically.
Any hint is more than welcome