Search code examples
pythonsqlalchemyflaskpython-elixir

Using Flask with Elixir and SQL alchemy


I am trying to use Elixir with Flask. Reason being using SQL Alchemy directly has me confused about the data insert on Many to Many relations. So I have created the models file and generated the tables I need.

For SQl alchemy I call from flask like this:

db = SQLAlchemy(app)

How to do same for Elixir? I have a model method for get_or_init on Entity so I am trying to use that as well.

When I try to use SQLAlchemy itself (since elixir is just wrapper) I get:

AttributeError: type object 'User' has no attribute 'query' where User is a model.

Solution

  • Although I haven't used Elixir myself, the issue with missing query is simple - you need to add the query property to the models yourself:

    class User(object):
        query = Session.query_property()