Ticket #870 (closed enhancement: fixed)
add support to define join-type in schema
| Reported by: | lvanderree | Owned by: | francois |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.5 Beta 2 |
| Component: | Generator | Version: | devel |
| Severity: | normal | Keywords: | join-type |
| Cc: |
Description
I would like to propose an extension to the schema-syntax, to allow it to contain a preferred join-type.
I would appreciate it if the schema could contain information regarding the preferred join type of a relation, to simplify the call to the join-method in the PropelQueryLanguage. The goal is to get the default join-type (left, right, inner) for a join from the schema, instead of always use inner-join by default.
I am working on an implementation to (recursively) process dotted relation-names, but when you define dotted-relation-names you cannot provide the join-type along with the name. However since you probably already know which join you want, when you define the relation, I think it would be nice if it would be possible to define the join-type in the schema, like:
For example in test/fixtures/bookstore/schema.xml
<table name="essay">
<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" description="Book Id" />
<column name="title" type="VARCHAR" required="true" primaryString="true" />
<column name="first_author" required="false" type="INTEGER" description="Foreign Key Author" />
<column name="second_author" required="false" type="INTEGER" description="Foreign Key Author" />
<column name="subtitle" type="VARCHAR" phpName="SecondTitle" />
<foreign-key foreignTable="author" onDelete="setnull" onUpdate="cascade">
<reference local="first_author" foreign="id" />
</foreign-key>
- <foreign-key foreignTable="author" onDelete="setnull" onUpdate="cascade">
+ <foreign-key foreignTable="author" preferedJoinType="LEFT JOIN" onDelete="setnull" onUpdate="cascade">
<reference local="second_author" foreign="id" />
</foreign-key>
</table>
Since the secondAuthor is optional you probably always want to use a left-join to retrieve the second-author while joining.
I've got a diff to support this all based on Propel1.5 beta1 that has extensions for
database.xsd
RelationMap.php
TableMap.php
ForeignKey.php
PHP5TableMapBuilder.php
ModelCriteria.php (for retrieving the prefered joinType for a given relation)
I have also updated the unit-tests to test this extension.
