私は他のテーブルとの(タイプDoctrine_Relation_Association
とDoctrine_Relation_ForeignKey
の)いくつかのオプションの関係を持つ教義テーブルを使用しています。そのテーブルのレコードが関連テーブルのレコードと接続しているかどうかをテストするにはどうすればよいですか。
これが私の質問をより明確にするための例です。ユーザーがいて、ユーザーがユーザーグループと多対多の関係を持ち、ユーザーが1つのユーザーロールを持つことができると仮定します。特定のユーザーがユーザーグループの一部であるか、ロールを持っているかをテストするにはどうすればよいですか。
解決策は私が信じているところから始まります
$relations = Doctrine_Core::getTable('User')->getRelations();
$user = Doctrine_Core::getTable('User')->findOne(1);
foreach($relations as $relation) {
//here should go a test if the user has a related record for this relation
if ($relation instanceof Doctrine_Relation_Association) {
//here the related table probably has more then one foreign key (ex. user_id and group_id)
}
if ($relation instanceof Doctrine_Relation_ForeignKey) {
//here the related table probably has the primary key of this table (id) as a foreign key (user_id)
}
}
//true or false
echo $result
ユーザーと他のテーブルの間にいくつの関係があっても機能する一般的なソリューションを探しています。
ありがとう!