Search code examples
pythonsqlalchemypython-elixir

How do you save models in Elixir


I've got a database created using Django models which I'm now accessing using SQLAlchemy and Elixir. The querying works and I can pull items out of the database perfectly happily but when I edit them and try to save them it throws the following exception:

>>> p = Problem.query.first()
>>> p
<Problem('Test Problem', 'This is a test problem so the database has something in it', 'SBMT')>
>>> p.name
u'Test Problem'
>>> p.name = "Test_Problem"
>>> p.save()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/elixir/entity.py", line 1116, in save
    return self._global_session.save(self, *args, **kwargs)
    AttributeError: 'Session' object has no attribute 'save'

What am I doing wrong? Have I missed a crucial part of the set up that is preventing me from saving things to the database or is it a problem with my versions of elixir and SQLAlchemy?

I've already run setup_all() and the metadata.bind is all set, hence I can query the database.


Solution

  • I'm no Elixir expert, but from the documentation it looks like it uses something called a global session.

    To save the changes to the database, you do a session.commit(), there's no save() method like in Django.