[sqlalchemy] Re: Possible to build a query object from a relation property?

2007-12-10 Thread Allen Bierbaum

Thanks.  This looks like it should work.  I will give it a try.

-Allen

On Dec 9, 2007 10:39 PM, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
>
> On Dec 9, 2007, at 10:55 PM, Allen Bierbaum wrote:
>
> >
> > I am using SA 0.3.11 and I would like to know if there is a way to get
> > a query object from a relation property.  I have several one-to-many
> > relationships in my application.  These are all setup and work very
> > well, but I find that I often want to perform further filtering of the
> > objects in the relationship list property.  I could write python code
> > to do it, but if I could get SA to do it on the server, then all the
> > better.
>
> it is the "dynamic" relation that you want, but for 0.3 you can write
> your own read-only property via:
>
> class MyClass(object):
> def _get_prop(self):
> return 
> object_session(self).query(ChildClass).with_parent(self,
> 'attributename')
>  attributename = property(_get_prop)
>
>
>
>
> >
>

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



[sqlalchemy] Re: Possible to build a query object from a relation property?

2007-12-09 Thread Michael Bayer


On Dec 9, 2007, at 10:55 PM, Allen Bierbaum wrote:

>
> I am using SA 0.3.11 and I would like to know if there is a way to get
> a query object from a relation property.  I have several one-to-many
> relationships in my application.  These are all setup and work very
> well, but I find that I often want to perform further filtering of the
> objects in the relationship list property.  I could write python code
> to do it, but if I could get SA to do it on the server, then all the
> better.

it is the "dynamic" relation that you want, but for 0.3 you can write  
your own read-only property via:

class MyClass(object):
def _get_prop(self):
return object_session(self).query(ChildClass).with_parent(self, 
 
'attributename')
 attributename = property(_get_prop)




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