私は propel の初心者で、propel の多対多の関係に関連する問題に直面しています。私は2つのテーブルを持っています。ユーザー:
<table name="users" phpName="User">
<!-- column and foreign key definitions go here -->
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="username" type="varchar" size="50" required="true" />
<column name="password" type="varchar" size="256" required="true" />
<unique>
<unique-column name="username"/>
</unique>
<index>
<index-column name="username"/>
</index>
<behavior name="timestampable"/></table>
企業:
<table name="companies" phpName="Company">
<!-- column and foreign key definitions go here -->
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="name" type="varchar" size="256" required="true" />
<behavior name="timestampable"/></table>
そしてこちらがブリッジテーブル
<table name="users_companies" isCrossRef="true">
<!-- column and foreign key definitions go here -->
<column name="user_id" type="integer" primaryKey="true" />
<column name="company_id" type="integer" primaryKey="true" />
<foreign-key foreignTable = "companies" phpName="Company">
<reference local="company_id" foreign="id"/>
</foreign-key>
<foreign-key foreignTable = "users" phpName="User">
<reference local="user_id" foreign="id"/>
</foreign-key>
<behavior name="timestampable"/>
</table>
ユーザーに関連する企業を取得しようとすると、
CompanyQuery::create() ->filterByUser($user)->find();
すべてのユーザーを正常に取得できます。ただし、会社に関連するすべてのユーザーを取得しようとすると
$user = UserQuery::create()->filterByCompany($company)->find();
私はユーザーを取得しません。生成されたSQLも確認しましたが、一方向の関係しかありません
CREATE TABLE `users_companies`(
`user_id` INTEGER NOT NULL,
`company_id` INTEGER NOT NULL,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`user_id`,`company_id`),
INDEX `users_companies_FI_1` (`company_id`)) ENGINE=MyISAM;
誰かが私が間違っていることを指摘できますか?