Cleverly observed :D yes it is only half the question. I guess pulling all lang-titles eager and then doing the decision programmatically is the feasible thing to to-do.
However =), traditionally you'd solve that problem by "select content.id as id, lang_str.title as title from content, lang_str, lang where lang_str.lang_id = lang.id and lang_str.content_id = content.id and lang.name := language and whatever else". That'd be a tad more efficient. Quoting Michael Bayer <[EMAIL PROTECTED]>: > this is only half of a question. what is the completed interface > youd like to see on the Content class, whereby i want the title in a > certain language? > > the solution, since it seems youre looking for something eager, would > involve just making a relation to load in all the titles represented > in the lang_str table for the "title" attribute, which would be named > something "hidden" like "_title", then implementing some interface on > Content that pulls from that already-loaded (or lazily-loaded) pool > of title fields. > > to make it more efficient to pull the title of a certain language > from this relation, you can subsitutite your own dictionary-like > object which has an "append" method for the "_title" attribute that > hashes based on the incoming language, as the mapper adds data to it. > > > On Mar 22, 2006, at 8:24 AM, Florian Boesch wrote: > > > A simple problem. Multi-language support. > > > > Say I have content which can have a title in different languages. > > So I have a > > > > content = Table('content', engine, > > Column('id', Integer, Sequence('content_seq'), primary_key=True)) > > > > so I also have a > > > > lang = Table('lang', engine, > > Column('id', Integer, Sequence('lang_seq'), primary_key=True), > > Column('name', String(255)) > > > > this contains things like VALUES('de') etc. > > > > lang_str = Table('lang_str', engine, > > Column('lang_id', Integer, ForeignKey('lang.id')), > > Column('content_id', Integer, ForeignKey('content.id')), > > Column('value', String(2048))) > > > > The problem is with the mapper and the relation to the title. > > > > class Content(object): pass > > contents = mapper(Content, content) > > contents.add_property('title', ...? > > > > etc. now the two questions. > > > > a) How do I make a relation that gives me the lang_str.value as > > it's value so > > I do not have to write somecontent.title.value > > > > b) How do I make the relation "customizable", i.e. I do not have to > > do many > > relations for each language I want support for (no > > mycontent.title_de.value, > > mycontent.title_en.value etc.? > > > > I do know how to customize for a fixed value via the secondaryjoin > > of relation, > > but I'm uncliear how I can parametrize this. (for that matter, I > > could of > > course write a member to my class who does this, but then I loose > > eager-loading > > for titles...) > > > > Cheers, > > Florian > > > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by xPML, a groundbreaking scripting > > language > > that extends applications into web and mobile media. Attend the > > live webcast > > and join the prime developer group breaking into this new coding > > territory! > > http://sel.as-us.falkag.net/sel? > > cmd=lnk&kid=110944&bid=241720&dat=121642 > > _______________________________________________ > > Sqlalchemy-users mailing list > > Sqlalchemy-users@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users > > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 > _______________________________________________ > Sqlalchemy-users mailing list > Sqlalchemy-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users > > ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users