Skip to content

Commit

Permalink
Added working table reflection.
Browse files Browse the repository at this point in the history
This fixes pallets-eco#55
  • Loading branch information
mitsuhiko committed Jul 31, 2013
1 parent 46569ca commit 1968a92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Version 2.0
for customizing session creation.
- If the ``bind`` parameter is given to the signalling session it will no
longer cause an error that a parameter is given twice.
- Added working table reflection support.

Version 1.0
-----------
Expand Down
11 changes: 7 additions & 4 deletions flask_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def get_binds(self, app=None):
retval.update(dict((table, engine) for table in tables))
return retval

def _execute_for_all_tables(self, app, bind, operation):
def _execute_for_all_tables(self, app, bind, operation, skip_tables=False):
app = self.get_app(app)

if bind == '__all__':
Expand All @@ -879,9 +879,12 @@ def _execute_for_all_tables(self, app, bind, operation):
binds = bind

for bind in binds:
tables = self.get_tables_for_bind(bind)
extra = {}
if not skip_tables:
tables = self.get_tables_for_bind(bind)
extra['tables'] = tables
op = getattr(self.Model.metadata, operation)
op(bind=self.get_engine(app, bind), tables=tables)
op(bind=self.get_engine(app, bind), **extra)

def create_all(self, bind='__all__', app=None):
"""Creates all tables.
Expand All @@ -905,7 +908,7 @@ def reflect(self, bind='__all__', app=None):
.. versionchanged:: 0.12
Parameters were added
"""
self._execute_for_all_tables(app, bind, 'reflect')
self._execute_for_all_tables(app, bind, 'reflect', skip_tables=True)

def __repr__(self):
app = None
Expand Down

0 comments on commit 1968a92

Please sign in to comment.