Hi everyone,
 
hopefully you can help us with this question.
 
In our project we have several "model" entities which have a many-to-one 
association to a corresponding "visualization" entity, which describes the 
entity in some way (like sort-orders). Each model entity has its one 
visualization entity. The visualization entities are stored in a single 
table via discriminators. In short (only important attributes, etc are 
shown) this is how this looks like:
 
/** @MappedSuperclass
 *
 **/
class SortableEntity   //<<<------ This class is just an attempt to have 
superclass which can be used in the entity "Visualization" as targetEntity. 
We actually don't need this entity.
{
        /**
         * @OneToMany(targetEntity="Visualization", mappedBy="id",
         *   cascade={"persist"})
         * @JoinColumn(name="key", referencedColumnName="descriptor_key")
         **/
        public $visualization;
}
 
 
 
/** @Entity
 *  @Table(name="measure___milestone")      **/
class Milestone extends SortableEntity
{
    /** @Id @GeneratedValue @Column(type="bigint", name="key") **/
    public $id;
 
   /**
     * @OneToMany(targetEntity="VisualizationMilestone", mappedBy="id",
     *   cascade={"persist"})
     * @JoinColumn(name="key", referencedColumnName="descriptor_key")
     **/
    public $visualization;
 
}
 
 
/**
 * @Entity
 * @Table(name="ent___visualization")
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="object_type", type="string")
 * @DiscriminatorMap({"measure_milestone"="VisualizationMilestone", 
"measure_financial_kpi"="VisualizationFinancialKPI", 
"measure_measure_kpi"="VisualizationKPI", "unit"="VisualizationUnit", 
"country"="VisualizationCountry", 
"business_unit"="VisualizationBusinessUnit","sub_region"="VisualizationSubRegion","region"="VisualizationRegion","sales_line"="VisualizationSalesLine","process"="VisualizationProcess"})
 */
class Visualization
{
       
    /**
     * @Id @ManyToOne(targetEntity="SortableEntity")
     * @JoinColumn(name="descriptor_key", referencedColumnName="key")
     **/
        protected $id;
 
}
 
 
/** @Entity  **/
class VisualizationMilestone extends Visualization
{
        /**
         * @Id @ManyToOne(targetEntity="Milestone")
         * @JoinColumn(name="descriptor_key", referencedColumnName="key")
         **/
        protected $id;
 
}

As you can see, the model entity has an association to the visualization 
entity and the visualization an association back to the model entity. And 
here lays our problem: It seems like doctrine is ignoring the targetEntity 
"Milestone" in the entity VisualizationMilestone (or our approach is wrong 
in the first place). When trying to create a new VisualizationMilestone 
entity we get an error.
 
Code for creating new entity:

$newMilestone   = $this->getOrCreateCachedObject('Milestone', 'setMeasure', 
$measure);
if($newMilestone instanceof Milestone) {

if(is_null($newMilestone->getDescription())) { 
$newMilestone->setDescription(''); }
if(is_null($newMilestone->getResult())) { $newMilestone->setResult(''); }
$newMilestone->setTitle($value);
$milestones = $measure->getMilestones();
$milestones->add($newMilestone);
$countMilestones = count($milestones);
$milestoneVisualization = new VisualizationMilestone();
$milestoneVisualization->setId($newMilestone);
$milestoneVisualization->setOrder($countMilestones);
$milestoneVisualization->setStyleClass('');
if(!Guard::checkDemoUserAuth()) {
$this->entityManager->flush();
}
$this->entityManager->persist($milestoneVisualization);
}


Error we get:

"An exception occurred while executing 'INSERT INTO ent___visualization 
(`order`, `style_class`, `descriptor_key`, `object_type`) VALUES (?, ?, ?, 
?)' with params 
{"1":43,"2":"","3":null,"4":"measure_milestone"}:SQLSTATE[23000]: Integrity 
constraint violation: 1048 Column 'descriptor_key' cannot be null"

I found this pull request <https://github.com/doctrine/doctrine2/pull/633> 
which added the functionality to override the targetEntity. Unfortunately 
it was closed with the comment, that this situation should never come up 
with a correct inheritance. In our case, where is our problem?
 
If anything is unclear, please just ask.
 
Many thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to