Search code examples
phpdatabasesymfonyarchitecturepropel

Propel 1.6 & Symfony 2: Bundle inheritance and schema dependancies


I have a src/SiteBundle that extends vendor/CoreBundle, and I want to add a "label" model / table to the SiteBundle schema.xml without duplicating the CoreBundle schema.xml. No problem, you say?! Bah!

The problem comes if the SiteBundle "label" table has a foreign key (e.g. label.product_id) that points to a table defined in the CoreBundle. Propel refuses to build the "label" Model because it thinks it has an unresolved column dependancy.

Is there a way to contextualise the two schema.xml files at build-time so that Propel understands that SiteBundle extends CoreBundle? I guess a simple schema.xml merge is what I'm after...

N.B. I've investigated Propel's notion of schema / model inheritance, but none of those solutions fit this problem.


Solution

  • Turns out that the Propel Bundle does let you contextualise the schema.xml files at build-time, either by setting the package attribute of both schema.xml files to the same thing

    <database name="site" namespace="Site\Bundle\Model" package="default">
        ...
    </database>
    

    or by setting

    propel.namespace.autoPackage: true
    

    Propel build properties documentation here.

    However, my problem actually came from the simple fact I'd misunderstood how Symfony2's bundle override method getParent() worked. My problem could be most cleanly solved by leaving the Propel config / schemas alone and by either;

    • removing the SiteBundle::getParent() method, or;
    • prefixing the SiteBundle schema.xml file with something (anything), so that Propel could get to both schema files, despite the getParent() override.