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

Primary key unique constraint inherited on tanslation table #27

Open
thanegill opened this issue Aug 20, 2020 · 0 comments
Open

Primary key unique constraint inherited on tanslation table #27

thanegill opened this issue Aug 20, 2020 · 0 comments

Comments

@thanegill
Copy link

thanegill commented Aug 20, 2020

When a model has a primary key unique constraint the child class translation table inherits this constraint, this then make the the translation table only able to hold one translation for each key.

Example:

class Message(Translatable, db.Model):
    __translatable__ = {
            'locales': ['en', 'es'],
            'fallback_locale': 'en',
        }
    key = db.Column(db.String(64), primary_key=True, nullable=False, unique=True)

class MessageTranslation(translation_base(Message)):
    __tablename__ = 'message_translation'
   text = db.Column(db.UnicodeText)

for locale in ['en', 'es']:
    message_translation = MessageTranslation(
            key='example_key',
            locale=locale,
            text='text',
        )
    db.session.add(message_translation)
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