Skip to content

Add a yaml example for specifying an identifier. #640

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

Merged
merged 2 commits into from
Nov 5, 2018

Conversation

trsteel88
Copy link
Contributor

Closes #639

@trsteel88
Copy link
Contributor Author

Actually, I don't think this is correct. I still get the warning Unable to generate an IRI for the item of type \"App\\Api\\Model\\MyNonDoctrineModel\"

@antograssiot
Copy link
Contributor

Do you have a getter on your property and enable the get on item operation ?

@trsteel88
Copy link
Contributor Author

Yes.

final class MyNonDoctrineModel
{
    /**
     * @var string
     */
    private $id;

    /**
     * @var Organisation
     */
    private $organisation;

    /**
     * @var Template
     */
    private $template;

    /**
     * @var float
     */
    private $price;

    public function __construct(Organisation $organisation, Template $template)
    {
        $this->organisation = $organisation;
        $this->template = $template;
        $this->id = $this->organisation->getId().'-'.$this->template->getId();
    }

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

@trsteel88
Copy link
Contributor Author

trsteel88 commented Nov 2, 2018

My resource looks like this

App\Api\Model\MyNonDoctrineModel:
    properties:
        identifier: [id]
    attributes:
        access_control: "is_granted('ROLE_USER')"
    itemOperations:
        get:
            method: GET
            path: /organisations-templates/{id}
            defaults:
                _api_receive: false
            controller: App\Api\Action\OrganisationTemplatePrice\ViewAction
    collectionOperations:
        get:
            method: GET
            path: /organisations-templates
            controller: App\Api\Action\OrganisationTemplatePrice\ListAction

It's definitely a configuration issue with defining the identifiers because what I have configured are not coming through when I do a dump within IdentifiersExtractor.php

If I override the array of identifiers within that code it works.

@antograssiot
Copy link
Contributor

isn't that

App\Api\Model\MyNonDoctrineModel:
    properties:
        id:
            identifier: true
...

instead ?

@trsteel88
Copy link
Contributor Author

trsteel88 commented Nov 2, 2018 via email

@trsteel88
Copy link
Contributor Author

You were right @antograssiot. Thanks!

@dunglas dunglas merged commit 76eb1e8 into api-platform:2.3 Nov 5, 2018
@dunglas
Copy link
Member

dunglas commented Nov 5, 2018

Thanks a lot @trsteel88 and @antograssiot, this kind of enhancements in the docs are very helpful!

@trsteel88
Copy link
Contributor Author

You're welcome!

@trsteel88 trsteel88 deleted the patch-1 branch November 5, 2018 10:40
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

Successfully merging this pull request may close these issues.

3 participants