0

I have collection with embedMany field "properties"

{
    "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

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

GFB
  • 345
  • 1
  • 5
  • 15

1 Answers1

0

This code snippet doesn't work because $propOptId variable is not integer. If wrap $propTypeId and $propOptId in intval then this code will work fine.

GFB
  • 345
  • 1
  • 5
  • 15