我有2个课程,我想使用急切的加载方式:
/**
* @MongoDB\Document(collection="wallet")
*/
class Wallet
{
/**
* @MongoDB\ReferenceMany(targetDocument="WalletEntry", mappedBy="wallet")
*/
protected $entries;
}
/**
* @MongoDB\Document(collection="wallet_entry")
*/
class WalletEntry
{
/**
* @MongoDB\ReferenceOne(targetDocument="Wallet", storeAs="id")
*/
protected $wallet;
}
$wallets = $doctrine->getRepository('App:Wallet')->findAll();
foreach ($wallets as $wallet) {
foreach ($wallet->entries as $entry) {
// ...
}
}
Field "entries" is not the owning side of a reference relationship in class "App\Document\Wallet"
:$wallets = $doctrine->createQueryBuilder('App:Wallet')
->field('entries')->prime(true)
->getQuery()
->execute();
如何使用紧急加载和仅2个查询将钱包及其条目一起加载?我没有在Wallet文档中保留任何引用,因为相应的WalletEntry文档的数量可能很大。