RESTful-Drupal / restful

RESTful best practices for Drupal
https://drupal.org/project/restful
418 stars 173 forks source link

Handling child entity references in the parent #1041

Open belambic opened 6 years ago

belambic commented 6 years ago

I watched the video tutorials by Mateus which were very useful, but the data model he is working with has the entity reference on the parent content type. Unfortunately the data model I'm working with has the entity reference on the child content type, like so:

Parent: Organization has no entity reference fields Child: Campaign has an entity reference field pointing to the organization

I want my organization resource to include relationships for each campaign associated with that organization. Is there a simple way to do that?

I've tried this, where $this->campaigns returns an array of nids, which didn't work:

// Add campaigns as references. $public_fields['campaigns'] = [ 'callback' => [$this, 'campaigns'], 'resource' => [ 'name' => 'campaign', 'majorVersion' => '1', 'minorVersion' => '0', ], ];