sess.query(Website).filter(Website.materials.any())

neat huh ?

that "materials=[]" declaration is not needed BTW, the collection  
defaults to an empty list due to the relation() set up on it.


On Sep 1, 2008, at 1:50 PM, Gustavo Narea wrote:

>
> Hello, everybody.
>
> In my model, I have a websites table and another table for the  
> badges for
> every website; where some web sites may not have a badge at all.
>
> So, I'm looking for a query which returns the websites that have at  
> least one
> badge; it doesn't matter how many badges they have, only _if_ they  
> have a
> badge.
>
> This is how my model looks like:
>
>> class Website(DeclarativeEntity):
>>    __tablename__ = 'website'
>>    website_alias = Column(Unicode(15), primary_key=True)
>>    materials = []
>>
>>
>> class Badge(DeclarativeEntity):
>>    __tablename__ = badge
>>    _website_alias = Column('website_alias', Unicode(15),
>>                            ForeignKey('website.website_alias'))
>>    badge_name = Column(Unicode(20), primary_key=True)
>>    website = relation('Website', backref='materials')
>
> Thanks in advance.
> -- 
> Gustavo Narea.
> General Secretary. GNU/Linux Matters.
> http://www.gnulinuxmatters.org/
>
> >


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