function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Cthulhu4242Cthulhu4242 

PHP 1.1 query with relationships is hurting my brain

Using the 1.1 PHP Toolkit (thanks, guys!), I have a lovely query which now gives me all the info I want at once. The trouble is how to access it. Here is my query and code to access it:

  Code:
$query = "SELECT Entitlement__r.Name, Id, Contact__c, Entitlement__c FROM Contact_Entitlement_Link__c where Contact__r.email = '$email'";
  $queryOptions = new QueryOptions(200);
  $response = $mySforceConnection->query(($query), $queryOptions);
  $entitlement = $response->records;

if ($entitlement) {
      foreach ($entitlement as $r) {
        $r = new SObject($r);
        .....

 

but here's where I get hazy... How do I display the info in the info in the related object?

$r->Id works great for the Id of the Contact_Entitlement_Link__c
$r->fields->Entitlement__c works great for the Id of the Entitlement__c

How do I get Entitlement__r.Name?

Thanks in advance.


Message Edited by Kingsley on 04-05-2007 04:38 PM

Tran ManTran Man
Is this for Partner or Enterprise?
Cthulhu4242Cthulhu4242
Partner as it is an extension of something I started doing with the old PHP toolkit that could only do Partner. I suppose there's no reason I couldn't do Enterprise now though. I guess this means there's a difference in how to do it based on which wsdl? I'd love to know both answers.

Thanks!
Tran ManTran Man
You need to wrap the response in a QueryResult like so to access the related objects:

Code:
  $response = $mySforceConnection->query(($query));
  $queryResult = new QueryResult($response);

   foreach ($queryResult->records as $record) {
     print_r($record);
   }



Cthulhu4242Cthulhu4242
Thanks for the help! That led me to what I needed to know. I can access the related field like this:

$r->sobjects[0]->fields->Name;