Revolution1 / Flask-WhooshAlchemyPlus

Whoosh indexing capabilities for Flask-SQLAlchemy, Flask-WhooshAlchemy plus some improvement
Other
68 stars 17 forks source link

Working without Flask_sqlalchemy #17

Open phuicy opened 5 years ago

phuicy commented 5 years ago

So currently this plugin won't work without Flask-sqlalchemy. Specifically, if you sqlalchemy-utils.

Solution: This section: https://github.com/Revolution1/Flask-WhooshAlchemyPlus/blob/1e7a79b6d12e85e3e0fd12eb70a8d6468642359a/flask_whooshalchemyplus.py#L255

is changed to:

    # change the query class of this model to our own
    if hasattr(model, 'query_class'):
        if model.query_class is not flask_sqlalchemy.BaseQuery \
                and model.query_class is not _QueryProxy:
            print(model.query_class, _QueryProxy)
            model.query_class = type(
                'MultipliedQuery', (model.query_class, _QueryProxy), {}
            )
        else:
            model.query_class = _QueryProxy
    else:
        model.query_class = _QueryProxy