Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Query using GROUP BY returning non parsed data #41

Open
thiagocoelho opened this issue Jul 1, 2015 · 0 comments
Open

Query using GROUP BY returning non parsed data #41

thiagocoelho opened this issue Jul 1, 2015 · 0 comments

Comments

@thiagocoelho
Copy link

Hi :)

I'm opening the issue as requested.

I was doing a query using GROUP BY and the result was a XML with namespace that can't be parsed.

Here is the query:

SELECT 
  Produto__r.Marca__r.Id,
  Produto__r.Marca__r.Name,
  Produto__r.Marca__c,
  Produto__r.Marca__r.Id_Box__c
FROM
  Veiculos__c
WHERE
  Ativo__c = true
GROUP BY
  Produto__r.Marca__r.Id,
  Produto__r.Marca__r.Name,
  Produto__r.Marca__c,
  Produto__r.Marca__r.Id_Box__c

The result:

[
  {
  Id: [
    "a02j00000046DZ7AAM",
    "a02j00000046DZ7AAM"
  ],
  any: "<sf:Name>Hyundai importados</sf:Name><sf:Marca__c>a02j00000046DZ7AAM</sf:Marca__c><sf:Id_Box__c>7</sf:Id_Box__c>"
  },
  {
  Id: [
    "a02j0000004kRhJAAU",
    "a02j0000004kRhJAAU"
  ],
  any: "<sf:Name>HB20</sf:Name><sf:Marca__c>a02j0000004kRhJAAU</sf:Marca__c><sf:Id_Box__c>5</sf:Id_Box__c>"
  }
]

I'm using a workaround for now, basically I'm removing the sf: namespace from the xml tags, adding the xml declaration with a root node and loading it as a xml string something like:

$result = $query->records;
$objects = [];

foreach($result as $obj) {
  $str = preg_replace('{sf:}', '', $obj->any);

  $xml = '<?xml version="1.0" encoding="UTF-8"?><obj>'.$str.'</obj>';

  $objects[] = simplexml_load_string($xml);
}

Best regards

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant