Propel2 icon indicating copy to clipboard operation
Propel2 copied to clipboard

set foreignSchema when schema is public

Open domcar opened this issue 9 years ago • 1 comments

Since Propel ignore the public schema of Postgres, there is a problem when in the schema.xml there is a foreign-key with reference to a foreignTable that is located in the public schema.

In this example the table approvals is in schema1 while the foreignTable orders is located in public, this generates a problem because the reverse-engineer will look for the foreignTable in schema1:

<table name="approvals" schema="schema1" idMethod="native" >
    <column name="orderid" phpName="Orderid" required="true"/>
    <foreign-key foreignTable="orders" name="approvals_orderid_fk">
      ..........
    </foreign-key>

With this fix it is possible to reference a foreignTable when it is in the public schema:

<table name="approvals" schema="schema1" idMethod="native" >
    <column name="orderid" phpName="Orderid" required="true"/>
    <foreign-key foreignTable="orders" foreignSchema="public" name="approvals_orderid_fk">
      ..........
    </foreign-key>

domcar avatar Jan 05 '17 14:01 domcar

Mh, the thing is: Setting the schema to "public" per default can be wrong, since "public" is not always the default schema in Postgres. We should actually find out in which schema the target table is located and place it in "schema" attribute if it differs to the default schema (which we need to find out by querying the database using SHOW search_path;). But about the last part I'm not so sure, because if we do not specify a schema, it should already use the search_path to find it in public.

marcj avatar May 26 '17 12:05 marcj