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 at 
http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_relation_collections
. 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