1

I have a propel shcema.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<database name="issue-tracker" defaultIdMethod="native">
    <table name="user" phpName="User">
        <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="username" type="varchar" size="32" required="true" />
        <column name="password" type="varchar" size="32" required="true"/>
        <unique>
            <unique-column name="username"/>
        </unique>   
    </table>
    <table name="issue" phpName="Issue">
        <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="title" type="varchar" size="255" required="true" />
        <column name="description" type="varchar" size="200" required="true" phpName="Description"/>
        <column name="user_id" type="integer" required="true"/>
        <foreign-key foreignTable="user">
            <reference local="user_id" foreign="id"/>
        </foreign-key>
    </table>
    <table name="tag" phpName="Tag">
        <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="title" type="varchar" size="255" required="true" />
        <unique>
            <unique-column name="title"/>
        </unique>   
    </table>
    <table name="issue_tag" isCrossRef="true" phpName="IssueTag">
        <column name="issue_id" type="integer" primaryKey="true"/>
        <column name="tag_id" type="integer" primaryKey="true"/>
        <foreign-key foreignTable="issue" onUpdate="CASCADE" onDelete="CASCADE">
            <reference local="issue_id" foreign="id"/>
        </foreign-key>
        <foreign-key foreignTable="tag" onUpdate="CASCADE" onDelete="CASCADE">
            <reference local="tag_id" foreign="id"/>
        </foreign-key>
    </table>
    <table name="user_issue" isCrossRef="true" phpName="UserIssue">
        <column name="user_id" type="integer" primaryKey="true"/>
        <column name="issue_id" type="integer" primaryKey="true"/>
        <foreign-key foreignTable="user" onUpdate="CASCADE" onDelete="CASCADE">
            <reference local="user_id" foreign="id"/>
        </foreign-key>
        <foreign-key foreignTable="issue" onUpdate="CASCADE" onDelete="CASCADE">
            <reference local="issue_id" foreign="id"/>
        </foreign-key>
        <unique>
            <unique-column name="issue_id"/>
        </unique>   
    </table>
</database>

When I run the propel generator, it generates duplicate fields in BaseUser.php

    protected $collIssues;
    protected $collIssuesPartial;

    protected $collIssues;

As you can see there are dublicate $collIssues field. If I remove the foreign key from the last table user_issue the problem disappears.

Can someone help me or at least explain, give me a hint how to fix this.

Thank you.

4

1 回答 1

2

问题是 Propel 正在从两个不同的地方添加一系列问题,一个来自外键 in issue,一个来自外键 in user_issue。这是一个简单的修复,您只需要使用该refPhpName属性。有关该属性的更多信息,请查看Propel 文档。foreign-key

<table name="issue" phpName="Issue">
    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
    <column name="title" type="varchar" size="255" required="true" />
    <column name="description" type="varchar" size="200" required="true" phpName="Description"/>
    <column name="user_id" type="integer" required="true"/>

    <!-- notice the additional attributes below -->
    <foreign-key foreignTable="user" phpName="Creator" refPhpName="CreatedIssues">
        <reference local="user_id" foreign="id"/>
    </foreign-key>
</table>

然后在您的代码中,您以Creator不同的方式访问这些字段:

$myIssues = $user->getCreatedissues();
$creatorUser = $issue->getCreator();
$issuesCreatedByUser = IssueQuery::create()
  ->filterByCreator($user)
  ->find();
于 2013-07-05T20:35:27.230 回答