Ejemplo n.º 1
0
    def save(self, commit=False):
        """Save the changes to the model.

        If the model has not been persisted
        then it adds the model to the declared session. Then it flushes the
        object session and optionally commits it.
        """
        if not has_identity(self):
            # Object has not been persisted to the database.
            session.add(self)

        if commit:
            # Commit the session as requested.
            session.commit()

        else:
            # Just flush the session; do not commit.
            session.flush()
Ejemplo n.º 2
0
    def save(self, commit=False):
        """Save the changes to the model.

        If the model has not been persisted
        then it adds the model to the declared session. Then it flushes the
        object session and optionally commits it.
        """
        if not has_identity(self):
            # Object has not been persisted to the database.
            session.add(self)

        if commit:
            # Commit the session as requested.
            session.commit()

        else:
            # Just flush the session; do not commit.
            session.flush()
Ejemplo n.º 3
0
    def test_save(self):
        from a.models import AWall

        # Create 2 models.
        AWall().save()
        AWall().save(commit=False)

        # Commit.
        from alchemist.db import session
        session.commit()

        # Query.
        assert len(session.query(AWall).all()) == 2

        # Fetch and save.
        m = session.query(AWall).first()
        m.id = 43526
        m.save()

        # Query.
        assert session.query(AWall).filter_by(id=43526).first() is not None