Unverified Commit 23a8c6aa authored by Serge S. Koval's avatar Serge S. Koval Committed by GitHub

Merge pull request #1648 from tandreas/fix_different_bind_joins

Fix scaffold_auto_joins for differnet binds.
parents 745620ad 92f077e0
...@@ -765,6 +765,12 @@ class ModelView(BaseModelView): ...@@ -765,6 +765,12 @@ class ModelView(BaseModelView):
if p.mapper.class_ == self.model: if p.mapper.class_ == self.model:
continue continue
# Check if it is pointing to a differnet bind
source_bind = getattr(self.model, '__bind_key__', None)
target_bind = getattr(p.mapper.class_, '__bind_key__', None)
if source_bind != target_bind:
continue
if p.direction.name in ['MANYTOONE', 'MANYTOMANY']: if p.direction.name in ['MANYTOONE', 'MANYTOMANY']:
relations.add(p.key) relations.add(p.key)
......
...@@ -2218,6 +2218,34 @@ def test_multipath_joins(): ...@@ -2218,6 +2218,34 @@ def test_multipath_joins():
eq_(rv.status_code, 200) eq_(rv.status_code, 200)
def test_different_bind_joins():
app, db, admin = setup()
app.config['SQLALCHEMY_BINDS'] = {
'other': 'sqlite:///'
}
class Model1(db.Model):
id = db.Column(db.Integer, primary_key=True)
val1 = db.Column(db.String(20))
class Model2(db.Model):
__bind_key__ = 'other'
id = db.Column(db.Integer, primary_key=True)
val1 = db.Column(db.String(20))
first_id = db.Column(db.Integer, db.ForeignKey(Model1.id))
first = db.relationship(Model1)
db.create_all()
view = CustomModelView(Model2, db.session)
admin.add_view(view)
client = app.test_client()
rv = client.get('/admin/model2/')
eq_(rv.status_code, 200)
def test_model_default(): def test_model_default():
app, db, admin = setup() app, db, admin = setup()
_, Model2 = create_models(db) _, Model2 = create_models(db)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment