Search code examples
php-5.3propel

Propel wrong table prefix with external schema


I am using propel orm as database abstraction layer. I want to define different schema.xml files for diffenrent modules. E.g. user.xml.schema for handling users and roles, or app.schema.xml for the application model.

My problem is, I want to reference to the user table of the user.schema.xml. I can handle this by the tag, but I want to use another table prefix for the user schema tables. Running propel-gen creates two sql files (one for the user.schema and one for the app.schema), but the problem is, that the user-schema tables are generated twice. First with correct table prefix of the user schema file and the others with the prefix of the app schema file. The foreign key also references to the wrong tables (that from the table with the prefix of the app.schema.xml).

I do not know any way to prevent this behaviour. Any hints?


Solution

  • You cannot add different table prefixes to one database, and there is no way to add a tablePrefix attribute on the table tag. Let me explain a bit more, I know, you can specify a tablePrefix per XML schema even for a same database, but it leads to errors if you try to add relationship.. I don't know whether it's a bug or not, AFAIK the tablePrefix should be defined at the table level… Without relationship, you'll get a clean SQL file (or two if you don't set the propel.packageObjectModel build property to true.

    You can read: http://www.propelorm.org/reference/schema.html. So I think, it's not possible to do what you would like to do unfortunately. BTW, what you want to achieve is called multi component data model in the Propel doc.