Skip to content

Commit

Permalink
Infer collection_name from __table__
Browse files Browse the repository at this point in the history
Model classes that have been defined in a declarative style are not guaranteed to have a `__tablename__` attribute.  For example, if they have been declared in a hybrid style with an embedded table:

    class example(base):
        __table__ = Table(...)

However even those declared just via a `__tablename_` will have a `__table__` attribute (created by the metaclass), so to infer the collection name in all cases we should use `__table__.name`.
  • Loading branch information
donkopotamus committed May 8, 2015
1 parent 4bed33f commit 507bdc9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion flask_restless/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def create_api_blueprint(self, model, app=None, methods=READONLY_METHODS,
app = self.app
restlessinfo = app.extensions['restless']
if collection_name is None:
collection_name = model.__tablename__
collection_name = model.__table__.name
# convert all method names to upper case
methods = frozenset((m.upper() for m in methods))
# sets of methods used for different types of endpoints
Expand Down

0 comments on commit 507bdc9

Please sign in to comment.