{"action":"closed","issue":{"url":"https://api.github.com/repos/flask-admin/flask-admin/issues/1250","repository_url":"https://api.github.com/repos/flask-admin/flask-admin","labels_url":"https://api.github.com/repos/flask-admin/flask-admin/issues/1250/labels{/name}","comments_url":"https://api.github.com/repos/flask-admin/flask-admin/issues/1250/comments","events_url":"https://api.github.com/repos/flask-admin/flask-admin/issues/1250/events","html_url":"https://github.com/flask-admin/flask-admin/issues/1250","id":145685417,"number":1250,"title":"Filters: models with multiple foreignkey to same model override","user":{"login":"buxx","id":1104637,"avatar_url":"https://avatars.githubusercontent.com/u/1104637?v=3","gravatar_id":"","url":"https://api.github.com/users/buxx","html_url":"https://github.com/buxx","followers_url":"https://api.github.com/users/buxx/followers","following_url":"https://api.github.com/users/buxx/following{/other_user}","gists_url":"https://api.github.com/users/buxx/gists{/gist_id}","starred_url":"https://api.github.com/users/buxx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buxx/subscriptions","organizations_url":"https://api.github.com/users/buxx/orgs","repos_url":"https://api.github.com/users/buxx/repos","events_url":"https://api.github.com/users/buxx/events{/privacy}","received_events_url":"https://api.github.com/users/buxx/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-04-04T13:36:01Z","updated_at":"2016-12-26T08:16:54Z","closed_at":"2016-12-26T08:16:54Z","body":"Hi,\n\nThis issue is related to  #909. If my admin view set column filters, but them columns are relationship on same model, last column override previous.\n\nThis code expose the bug (`Company.members` and `Company.contacts` are relations on same model):\n\n```\n# -*- coding: utf-8 -*-\nfrom flask import Flask\nfrom flask.ext.admin import Admin\nfrom flask.ext.admin.contrib.sqla import ModelView\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'\ndb = SQLAlchemy(app)\n\n\nclass User(db.Model):\n    id = db.Column(db.Integer, primary_key=True)\n    username = db.Column(db.String(128), unique=True)\n\n    company_member_id = db.Column(db.Integer(), db.ForeignKey('company.id'))\n    company_contact_id = db.Column(db.Integer(), db.ForeignKey('company.id'))\n\n    company_member = db.relationship(\"Company\", foreign_keys=[company_member_id], back_populates=\"members\")\n    company_contact = db.relationship(\"Company\", foreign_keys=[company_contact_id], back_populates=\"contacts\")\n\n\nclass Company(db.Model):\n    id = db.Column(db.Integer, primary_key=True)\n    name = db.Column(db.String(128), unique=True)\n\n    members = db.relationship(\"User\", foreign_keys=\"[User.company_member_id]\", back_populates=\"company_member\")\n    contacts = db.relationship(\"User\", foreign_keys=\"[User.company_contact_id]\", back_populates=\"company_contact\")\n\n\nclass CompanyView(ModelView):\n    column_filters = (\"members.username\", \"contacts.username\")\n\nadmin = Admin(app)\nadmin.add_view(CompanyView(Company, session=db.session))\n\n\nif __name__ == '__main__':\n    db.create_all()\n    app.run()\n```\n\nResult is:\n![selection_003](https://cloud.githubusercontent.com/assets/1104637/14249513/612ba38c-fa7a-11e5-9621-bb9a805f6228.png)\n\nIf i do filter with admin UI `User / Username` field, join will be on Company.contacts. It can be fixed ? \n\nThank's !\n"}}
{"actor":{"display_login":"petrus-jvrensburg"}}