On Jan 20, 2009, at 11:34 AM, Georg Schmid wrote:

>
> I'm trying to build up the model I need in my current project, but I'm
> also having a few issues with implementing properties of the following
> kind. I want to add a property to one of my mappers. This property is
> supposed to refer to a different object, only given the id (primary
> key of the table, naturally) and the mapper of the referred-to object.
> Right now all I've managed to do is fetch the corresponding id using a
> subquery - so how would I proceed to get the actual object from this
> subquery result?
>
> To my knowledge this cannot be solved by using a relation() property,
> since the secondary table that joins both classes might have multiple
> rows expressing this relationship, and more importantly, it is
> 'expressed in another class mapping' already. You might say, that to
> some degree this makes the desired property redundant, but as noted
> before, there can be duplicates of these relations and I want to run a
> grouped query on it to filter them out.
>
> If anything about my problem's unclear please go ahead, ask away and
> I'll sketch out the involved tables.
> Thanks in advance!


the general way to get an object where you have a subquery which  
returns an id is  
session.query(cls).filter(cls.id==mysubquery.as_scalar()).one().   I  
would note that if you're considering using a relation() with  
"secondary", yet the secondary table is explicitly mapped elsewhere,  
that's entirely acceptable if you set viewonly=True on the relation().

feel free to send along a demo of the tables in question.

--~--~---------~--~----~------------~-------~--~----~
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