从使用不同关系的表中进行选择

时间:2021-04-29 15:43:47

I have three tables (objects). The Foo table has a 1:N relationship defined with the table Bar. The table FooBar is used to define a different N:M relationship between A and B.

我有三个表(对象)。 Foo表具有与表Bar定义的1:N关系。表FooBar用于定义A和B之间的不同N:M关系。

I want to select all objects in Foo which have either a 1:N relationship with Bar and/or a N:M relationship using the same Criteria. So far, what I have is two different Criteria for each:

我想选择Foo中与Bar有1:N关系和/或使用相同Criteria的N:M关系的所有对象。到目前为止,我所拥有的是两个不同的标准:

  $c1n = new Criteria();  
  $c1n->addJoin(FooPeer::ID, BarPeer::FOO_ID);

  $cnm = new Criteria();  
  $cnm->addJoin(FooPeer::ID, FooBarPeer::FOO_ID); 

  $objects1N = FooPeer::doSelect($c1n);  
  $objectsNM = FooPeer::doSelect($cnm);  

Is it possible to include both in the same criteria? And if it is, how can I achieve that?

是否可以将两者都包含在相同的标准中?如果是,我怎么能实现呢?

1 个解决方案

#1


You can't do this directly, but see if this works for what you are looking for:

你不能直接这样做,但看看这是否适用于你正在寻找的东西:

find query for many to many relation propel

查找多对多关系的查询推进

You should be able to easily hydrate the 1:N relationship.

你应该能够轻松地保持1:N的关系。

foreach($query as $result) {
    $result->getBar()->getColumnName();
}

#1


You can't do this directly, but see if this works for what you are looking for:

你不能直接这样做,但看看这是否适用于你正在寻找的东西:

find query for many to many relation propel

查找多对多关系的查询推进

You should be able to easily hydrate the 1:N relationship.

你应该能够轻松地保持1:N的关系。

foreach($query as $result) {
    $result->getBar()->getColumnName();
}