Christian Démolis wrote:
> Cool, it's very powerful, it will allow me to save my Bandwidth
> because i take just what i want and not the entire object.
>
> Thanks Conor
>

I think I gave you the wrong impression: association_proxy does not
replace the original relation in any way. You are still using a full
SELECT when using the association_proxy, because the association_proxy
does its thing outside of SQL.

If you need to pick and choose columns in the SELECT statement, I would
advise doing that in the query:
q = session.query(Utilisateur.Login)
q = q.join(Utilisateur.verouillage)
q = q.filter(Verouillage.id == some_id)
logins = q.all()

Alternatively, you can look into using the sqlalchemy.orm.defer query
option to tell the query to NOT load a given column when loading a given
class. More info at
http://www.sqlalchemy.org/docs/05/reference/orm/query.html#query-options.

-Conor

> 2009/11/24 Conor <[email protected]
> <mailto:[email protected]>>
>
>     Christian Démolis wrote:
>     > Thx for your answer Thomas
>     >
>     > I want the attribute to not return the complete object just some of
>     > the attribute of the other table.
>     >
>     > In my case Utilisateur has some attributes : Login, Nom, Prenom, ...
>     > I dont want Verouillage.LeNomDuUtilisateur to return complete object
>     > Utilisateur
>     > I want it to return only Login attributes.
>     >
>     > Primaryjoin seems to work on condition (where clause) and not on
>     > select condition (select ... in a query)
>     >
>     > Is it possible to limit selected attributes in the relation?
>     >
>
>     You can use sqlalchemy.ext.associationproxy.association_proxy to
>     turn a
>     collection of related objects into a collection of related object
>     attributes:
>     _LeUtilisateur = relation(Utilisateur,
>     backref=backref('verrouillage'))
>     LeNomDuUtilisateur = association_proxy('_LeUtilisateur', 'Login')
>
>     -Conor
>
>     > 2009/11/24 Tefnet Developers - Tomasz Jezierski
>     <[email protected] <mailto:[email protected]>
>     > <mailto:[email protected] <mailto:[email protected]>>>
>     >
>     >     Dnia 2009-11-24, Wt o godzinie 11:18 +0100, Christian
>     Démolis pisze:
>     >     > Is it possible to put a filter on a relation in the
>     declaration?
>     >     >
>     >     > Example :
>     >     > LeNomDuUtilisateur = relation(Utilisateur,
>     >     > filter_by=Utilisateur.Login, backref=backref('verrouillage'))
>     >
>     >     I'm not sure what exactly your example means.. but if you
>     want extra
>     >     filters on relation, you can change primaryjoin
>     >    
>     
> http://www.sqlalchemy.org/docs/05/mappers.html#specifying-alternate-join-conditions-to-relation
>     >
>     >     something like:
>     >     LeNomDuUtilisateur = relation(Utilisateur,
>     >     primaryjoin=sqlalchemy.and_(defaultjoincondition,
>     >     yourextrafiltercondition), backref='verrouillage')
>     >
>     >
>     >     Tomasz Jezierski
>     >     Tefnet
>     >     www.tefnet.pl <http://www.tefnet.pl> <http://www.tefnet.pl>
>     >
>

--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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