A way to normalize this:

article_table:
id

title_table:
article_id = primary key, also = foreign key to article_table.id
language
title

content_table:
article_id = primary key, also = foreign key to article_table.id
language
content

mapper(Article, article_table, properties={
    'titles':relation(Title),
    'contents':relation(Content) } )

mapper(Title, title_table)
mapper(Content, content_table)

Now you can assign an article as many titles in as many languages as
you wish, and as many content fields in as many language as you wish.
You could extend this further in many ways.  It is even possible to
use a dictionary-like class as the collection class for the relations
in the Article mapper, so that you could work like this:

a=Article()
a.title['en']='Confusion in Ten Easy Steps'
a.title['fr']='...'
a.title['ru']='...'   (etc.)

So, this approach means no need to alter your schema, change any
classes, or alter any tables when you add or remove a language.  You
could keep a table of currently accepted languages and use that (via
foreign key) to check the integrity of the 'language' column on the
title and content tables, and so forth.

This technique, generally speaking, is known as Vertical Partitioning
or a 'Vertical Tables' approach, because it results in "tall, skinny"
tables as opposed to tables that are many columns wide.  Each
separable, changeable attribute that you might wish to add to an
article can have its own table instead of a field in the articles
table, and foreign keys from these tables back to the main article
table give sqlalchemy the information it needs to make articles
respond with integrity as a coherent class despite the normalization/
separation of data.  Of course, to do this you have to use a database
that is good with foreign keys.

On Nov 18, 2:31 pm, g00fy <[EMAIL PROTECTED]> wrote:
> hi
> so i have list of languages (suffixes)
> en
> de
> pl
> ru
>  etc...
>
> now i have my article_table, when normaly i would have columns:
> id, title, content
>
> but now i want to have:
> id, title_en, title_de, title_pl,
> title_ru,....,content_en,..,content_ru
>
> how can i create table definition "dynamicly" according to languages i
> have ?
> [I am aware that i will have to alter my table when I will add or
> remove a language]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to