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

The REST api generator expects the entity object has a primary key field named "id" with a getId() method. #10

Open
davidwdan opened this issue Sep 17, 2014 · 7 comments

Comments

@davidwdan
Copy link
Member

No description provided.

@vpassapera
Copy link

vpassapera commented Mar 5, 2015

[Removed]

Original link was showing https://github.com/vpassapera/TdnForgeBundle as an example on how identifiers could be supported with any name, but ended up writing a different bundle altogether.

@iBasit
Copy link

iBasit commented Jun 4, 2015

what is the solution? the above link does not work.

@davidwdan
Copy link
Member Author

At the moment the bundle does not handle primary key fields that are not named 'id'.

The link you want to look at is: https://github.com/TheDevNetwork/TdnPilotBundle

@iBasit
Copy link

iBasit commented Jun 4, 2015

I'm not sure if you planned to update more, but if you do, can you also add https://github.com/nelmio/NelmioApiDocBundle on the methods which are generated automatically. this would be basic stuff.

and plus support for custom primary key (maybe by when generating entity.. (it only changes small thing..)

@davidwdan
Copy link
Member Author

I did not include the DocBundle in this project, because it's an unnecessary dependency and it's very easy to add manually.

Using custom primary keys is still on the list of future changes. Pull requests are welcome.

@jhonatanTeixeira
Copy link

Hello guys, i had this problem on an entity containing id field with an getId function, but that is on a single inheritance structure, and therefore, this method is on a parent class

@vpassapera
Copy link

vpassapera commented Aug 30, 2016

Sorry, didn't see that people were commenting on this. I fixed this by using doctrine's metadata class to get the identifier.

I will update the top link as well:

https://github.com/vpassapera/TdnForgeBundle (The pilotbundle was what it was originally, but it was for a project for UCSF). TdnForgeBundle was the bundle that came out of that, but it didn't pick up and a better one was presented at Symfony SF 2014. If people have an interest in the bundle I can pick up development again.

The specific line that does it is this:
https://github.com/vpassapera/TdnForgeBundle/blob/develop/Generator/Traits/DoctrineMetadata.php#L70

But as you can see, it uses ClassMetadata from doctrine. (Doctrine\ORM\Mapping\ClassMetadata)

In this bundle, they are already using the metadata, the only reason it's not supported is because:

https://github.com/voryx/restgeneratorbundle/blob/master/src/Voryx/RESTGeneratorBundle/Generator/DoctrineRESTGenerator.php#L66

Which seems silly not to pass it to where it is needed, but either way, hope this helps.

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

4 participants