Вы можете присоединиться к двум коллекциям в Монго, используя поиск, который предлагается в версии 3.2. В вашем случае запрос будет
db.comments.aggregate({
$lookup:{
from:"users",
localField:"uid",
foreignField:"uid",
as:"users_comments"
}
})
, или вы также можете присоединиться к пользователям, тогда будет небольшое изменение, как указано ниже.
db.users.aggregate({
$lookup:{
from:"comments",
localField:"uid",
foreignField:"uid",
as:"users_comments"
}
})
Он будет работать так же, как левое и правое соединение в SQL.
Спасибо Paulw11 за подтверждение того, что проблема была вызвана реализацией кода в расширении из UIViewController
. Это приводило к странному поведению, в результате чего код вызывался не так, как обычно.
При переносе в общий подкласс из UIViewController
все проблемы были решены:
adaptivePresentationStyle
никогда не вызывался. viewControllerForAdaptivePresentationStyle
вызывается только в том случае, если ему предшествует тег @objc
. Исправленный код выглядит следующим образом для тех, кто ищет ту же функциональность.
class CustomViewController: UIViewController {
func showPopover(ofViewController popoverViewController: UIViewController, originView: UIView) {
popoverViewController.modalPresentationStyle = UIModalPresentationStyle.popover
if let popoverController = popoverViewController.popoverPresentationController {
popoverController.delegate = self
popoverController.sourceView = originView
popoverController.sourceRect = originView.bounds
popoverController.backgroundColor = popoverViewController.view.backgroundColor
popoverController.permittedArrowDirections = UIPopoverArrowDirection.any
}
self.present(popoverViewController, animated: true)
}
}
extension CustomViewController: UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyle(for: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.none
//return UIModalPresentationStyle.fullScreen
}
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
if traitCollection.horizontalSizeClass == .compact {
return UIModalPresentationStyle.none
//return UIModalPresentationStyle.fullScreen
}
//return UIModalPresentationStyle.fullScreen
return UIModalPresentationStyle.none
}
func presentationController(_ controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
switch style {
case .fullScreen: // Configuration for full-screen
default:
return controller.presentedViewController
}
}
}