简体   繁体   English

Doctrine ODM-通过embedMan集合实体获取实体

[英]Doctrine ODM - get entities by embedMany collection entities

I have collection with embedMany field "properties" 我有embedMany字段“属性”的集合

{
    "title": "Castle in Scotland",
    "properties": {
      "0": {
        "_id": NumberInt(13),
        "propType": {
          "$ref": "listing_property_types",
          "$id": NumberInt(9),
          "$db": "real_estate" 
        },
        "propOption": {
          "$ref": "listing_property_options",
          "$id": NumberInt(13),
          "$db": "real_estate" 
        } 
      },
      "1": {
        "_id": NumberInt(15),
        "propType": {
          "$ref": "listing_property_types",
          "$id": NumberInt(10),
          "$db": "real_estate" 
        },
        "propOption": {
          "$ref": "listing_property_options",
          "$id": NumberInt(15),
          "$db": "real_estate" 
      }
    } 
}

How to build query if I want to get entity where has propery with propType.$id=9 and propOption=13 如果要获取具有propType。$ id = 9和propOption = 13的属性的实体,如何构建查询

I try this 我尝试这个

$builder = $this->createQueryBuilder()->select();
foreach ($propertiesArr as $propTypeId => $propOptId) {
    if (intval($propTypeId) > 0 && intval($propOptId) > 0) {
        $builder->addOr(
            $builder->expr()
                ->field('properties.propType.$id')->equals($propTypeId)
                ->field('properties.propOption.$id')->equals($propOptId)
            );
        }
    }
}

but it doesn't work 但这不起作用

This code snippet doesn't work because $propOptId variable is not integer. 此代码段无效,因为$ propOptId变量不是整数。 If wrap $propTypeId and $propOptId in intval then this code will work fine. 如果将$ propTypeId和$ propOptId包装为intval,则此代码可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM