On Jan 20, 5:45 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> 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.

Thanks, using relation() perfectly suits my needs then.

On a side note, could you give me a hint on what's the difference
between deferred and lazy loading? I suspect it's exactly the same
thing, except one for columns only and the other one for relation()s.
I'd be thankful if you could clear up that mystery to me though, I
really want to get all these concepts straight. I'm working on paper
about Object Relational Mapping right now, for which I'm heavily
relying on SA to explain some common patterns and techniques (The
paper's a project for graduation in my local equivalent to high
school).
--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to