Skip to content

how to use @RelationProvider #315

@TOTOleHero

Description

@TOTOleHero

Hello,

I don't understand how to use the annotation @RelationProvider. The current object is never available on all methods (exp(), object::static() or func() )

How to get the current object to iterate on elements from his method ?

example :

namespace App\Entity;

/*
* @Hateoas\Relation( ??? ... object.getOtherObjects() ... ??? )
*/
class MyObject
{

    /**
     * @ORM\ManyToMany(targetEntity=MyOtherObject::class, inversedBy="myObjects")
     */
    private $otherObject;

...
    public function getOtherObjects()
    {
        return $this->otherObject;
    }
...

}


class MyObject
{

...
     public function getId()
    {
        return $this->id;
    }
...
}

To generate ...

{
  "_links": {
    "otherObjects": [
      {"href": "/api/otherObject/1"},
      {"href": "/api/otherObject/6"},
      {"href": "/api/otherObject/78"}
    ]
  }
}

thank's you

Activity

kryptychon

kryptychon commented on Sep 27, 2021

@kryptychon

Hi @TOTOleHero,

I've got the exact same question. As far as I understand the RelationProvider construct, it's not meant to provide Relations in realtime, but provide a single place where you can provide parsed Relation (expressions) which then can be cached.

I did not read the code to the end, but I guess all a RelationProvider does is providing a collection of cachable Relation metadata from one place.

However I think you use case should be adressed with @Embedded.

Please, someone correct me if I'm wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @TOTOleHero@kryptychon

        Issue actions

          how to use @RelationProvider · Issue #315 · willdurand/Hateoas