Thanks, that works.

But now, with the attribute_mapped_collection, every language is
queried and assigned to the dict (quite an overhead in my use-case).

how could i achieve to load only a selected language which is
dynamically assigned on the query?

i thought of something like a column_property which reads a param or
option passed to the query. is this possible?
or is another approach better?

Dom


On Dec 3, 7:13 pm, Simon <[EMAIL PROTECTED]> wrote:
> That would be
>
> desc = session.query(I18Product).filter_by(id=1183, lang="en").one()
>
> The Problem with your query is that you query() for Product, not for
> I18NProduct, so regardless of and filter and join functions you
> specify, you will always receice Product objects. Think of "query
> (Product)" as a final filter which creates Product objects from the
> returned rows, and ignores everything which is not a column of
> Product.
>
> For x.i18n (a property of Product) to work as you described, have a
> look 
> athttp://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_relatio...
> . You'd basically want to setup your relation() as a dict using the
> lang column as key.
>
> Simon
>
> On 3 Dez., 16:33, Dom <[EMAIL PROTECTED]> wrote:
>
> > Hi
>
> > i tried the following example, but i cant get the join to work:
>
> > CREATE TABLE product (
>
> >    id                INTEGER,
> >    price           NUMERIC(15,2) NOT NULL,
>
> >    PRIMARY KEY(id)
> > );
>
> > CREATE TABLE i18n_product (
> >    id                       INTEGER,
> >    lang                   VARCHAR(2),
> >    description        VARCHAR(150) NOT NULL,
>
> >    PRIMARY KEY(id, lang),
> >    FOREIGN KEY(id) REFERENCES product(id)
> > );
>
> > python:
>
> > class Product(Base):
> >     __table__ = Table('product', Base.metadata, autoload=True)
>
> > class I18NProduct(Base):
> >     __table__ = Table('i18n_product', Base.metadata, autoload=True)
> >     product = relation(Product, backref=backref('i18n'))
>
> > x=session.query(Product).filter(Product.id==1183).join('i18n').filter
> > (I18NProduct.lang=='en').one()
>
> > the sql looks of the JOIN looks good, but if i access x.i18n, another
> > queries is build which returns all of my language entry for one
> > product, what i try to get is one product description in the given
> > language.
>
> > please tell me how to do that correctly, thank you :)
>
> > cheers
> > Dom
>
>
--~--~---------~--~----~------------~-------~--~----~
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