Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No version for one to many relationships. #346

Open
gauravrajfm opened this issue Nov 16, 2023 · 1 comment
Open

No version for one to many relationships. #346

gauravrajfm opened this issue Nov 16, 2023 · 1 comment

Comments

@gauravrajfm
Copy link

gauravrajfm commented Nov 16, 2023

I'm using sqlalchemy-continuum version 1.4.0 for testing the versioning capabilities.
Defined following classes according to documentation -

make_versioned(user_cls=None)

class Article(Base):
    __versioned__ = {}
    __tablename__ = 'article'

    id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
    name = sa.Column(sa.Unicode(255))
    content = sa.Column(sa.UnicodeText)


class Tag(Base):
    __tablename__ = 'tag'
    __versioned__ = {}

    id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
    name = sa.Column(sa.Unicode(255))
    article_id = sa.Column(sa.Integer, sa.ForeignKey(Article.id))
    article = sa.orm.relationship(
        Article,
        backref=sa.orm.backref(
            'article_tags',
            lazy='dynamic'
        )
    )

sa.orm.configure_mappers()


# Initialized the entities like this -
article = Article(
            name=u'Some article 2'
        )
tag1 = Tag(name="A2T1", article=article)
tag2 = Tag(name="A2T2", article=article)

db.session.add(article)
db.session.add_all([tag1, tag2])
db.session.commit()
tag3 = Tag(name="A2T3", article=article)
db.session.add(tag3)
db.session.commit()


# Accessed the entity like this - 
article_id = int(request.args.get('id'))
sample_article = db.session.query(Article).filter(Article.id == article_id).first()
first_version = sample_article.versions[0]
second_version = first_version.next

The second_version is always None. It is not loading the next version. I've tried updating this entity multiple times yet the result remains the same.

What could be wrong here ?

@gauravrajfm
Copy link
Author

Tried using the method you suggested -

t1 = Tag(name="A2T1")
article = Article(name="Some article 2", article_tags=[t1])
db.session.add_all([article, t1])
db.session.flush()

t2 = Tag(name="A2T2")
article.article_tags.append(t2)
db.session.add(t2)
db.session.commit()

This also doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant