jfinkels / flask-restless

NO LONGER MAINTAINED - A Flask extension for creating simple ReSTful JSON APIs from SQLAlchemy models.
https://flask-restless.readthedocs.io
GNU Affero General Public License v3.0
1.02k stars 301 forks source link

flask_restless.manager.IllegalArgumentError: Provided model must have an `id` attribute #676

Open pekof opened 6 years ago

pekof commented 6 years ago

I'm working with legacy database table where primary key is not named id but JobID or ID, so when I try

manager.create_api(PhClientOut, primary_key='JobID', methods=['GET'])

I get error File "D:/0work/Transfer/central/central.py", line 125, in <module> manager.create_api(ClientOut, methods=['GET'], primary_key='JobID') File "C:\Users\frane\AppData\Local\Continuum\Anaconda3\lib\site-packages\flask_restless\manager.py", line 830, in create_api blueprint = self.create_api_blueprint(blueprint_name, *args, **kw) File "C:\Users\frane\AppData\Local\Continuum\Anaconda3\lib\site-packages\flask_restless\manager.py", line 604, in create_api_blueprint raise IllegalArgumentError(msg) flask_restless.manager.IllegalArgumentError: Provided model must have anidattribute

There should be way to define alternative id attribute name.

rudaporto commented 6 years ago

Which version are you using?

Can you try the current master branch?

pekof commented 6 years ago

flask-restless==1.0.0b1

flask==0.12.2 flask-babel==0.11.2 Flask-Bootstrap==3.3.7.1 flask-sqlalchemy==2.3.2

I will see if I could run master

pekof commented 6 years ago

It's working with current master branch

jayarajanjn commented 4 years ago

You can define a new id field just in the model and map it the relevant primary key column.