How to programmatically add / remove entity mapping

I have a handler that uses the same Entityfor two different types 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>
}

First handler method is performed in the old DB table, and it will display all fields need annotated using @ORM\Column( id, idInstrum, idDevice, instrumType). To do this, I use a primitive query and match the data withResultSetMapping

   $rsm = new ResultSetMapping;
   $rsm->addEntityResult('Belka\Iso50k1Bundle\Entity\PhyMeter', 'mt');
   $rsm->addFieldResult('mt', 'id', 'id');
   ...

and it works like a charm. The problem lies in the way of another handler, which must be stored in the table app.meter: what I really wanted to keep - this is a small part of the property (ie only id, idInstrumbut not instrumTypeto have this column in my new table schema.

StaticPHPDriver, , : / ORM- (.. )

? (@ORM\Column ). , ResultSetMapping, .

+4

Source: https://habr.com/ru/post/1658020/


All Articles