簡體   English   中英

Doctrine ODM-通過embedMan集合實體獲取實體

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

我有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" 
      }
    } 
}

如果要獲取具有propType。$ id = 9和propOption = 13的屬性的實體,如何構建查詢

我嘗試這個

$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)
            );
        }
    }
}

但這不起作用

此代碼段無效,因為$ propOptId變量不是整數。 如果將$ propTypeId和$ propOptId包裝為intval,則此代碼可以正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM