Using abstract subclass in Doctrine : curious database generation
07:55 07 Sep 2015

I'm currently working on an Symfony2 / MySQL project using Doctrine2. In our conception, we have a "super" abstract class which is extended by abstract subclasses which are themselves extended by concrete classes.

Here's my code:

id;
    }

    /**
     * Set libellé
     *
     * @param string $label
     * @return SuperAbstractClass
     */
    public function setLabel($label)
    {
        $this->label = $label;

        return $this;
    }

    /**
     * Get libellé
     *
     * @return string 
     */
    public function getLabel()
    {
        return $this->label;
    }
}
?>

And then:

sousLibelle = $sousLibelle;

        return $this;
    }

    /**
     * Get sous-libellé
     *
     * @return string 
     */
    public function getSousLibelle()
    {
        return $this->sousLibelle;
    }
}
?>

And here's my last code:

details = $details;

        return $this;
    }

    /**
     * Get details
     *
     * @return string 
     */
    public function getDetails()
    {
        return $this->details;
    }
}
?>

When I generate my SQL code, I get:

CREATE TABLE superabstractclass (id INT AUTO_INCREMENT NOT NULL, libelle LONGTEXT NOT NULL, discr VARCHAR(2) NOT NULL, PRIMARY KEY(id)) 
DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE abstractclass (id INT NOT NULL, subLabel LONGTEXT NOT NULL, PRIMARY KEY(id)) 
DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE concreteclass1 (id INT NOT NULL, details LONGTEXT NOT NULL, PRIMARY KEY(id)) 
DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE concreteclass2 (id INT NOT NULL, detailsautres LONGTEXT NOT NULL, PRIMARY KEY(id)) 
DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;

ALTER TABLE abstractclass 
ADD CONSTRAINT FK_438A1A85BF396750 FOREIGN KEY (id) 
REFERENCES superabstractclass (id) ON DELETE CASCADE;

ALTER TABLE concreteclass1 
ADD CONSTRAINT FK_474E75CFBF396750 FOREIGN KEY (id) 
REFERENCES superabstractclass (id) ON DELETE CASCADE;

I'm a bit surprised by the last line. Why is my concreteclass1 table referencing the superabstractclass (see *FK_474E75CFBF396750*) and not the abstractclass. I'm worrying for my data integrity : what would happen if I delete an abstractclass line. I would still have a superabstractclass and a concreteclass1 line (meaning object instances) but I would have lost some pieces of information on my objects.

Am I missing somethin ? I've been searching for few hours now but wasn't able to find anything. Thank you for any help.

php mysql symfony doctrine-orm