Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use @RelationProvider #315

Open
TOTOleHero opened this issue Feb 25, 2021 · 1 comment
Open

how to use @RelationProvider #315

TOTOleHero opened this issue Feb 25, 2021 · 1 comment

Comments

@TOTOleHero
Copy link

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

@kryptychon
Copy link

kryptychon commented Sep 27, 2021

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants