> On Sat, Apr 22, 2006 at 12:30:40PM +0200, Julien Seiler wrote:
> > Food(SQLObject):
> > name = StringCol()
> > brand = StringCol(default=None)
> > categories = RelatedJoin("Category")
> >
> > Category(SQLObject):
> > name = StringCol()
> > description = StringCol()
> > foods = RelatedJoin("Food")
>
> > I would like to query all foods in a given category with a given brand
>
> cat = Category.get(id)
> for food in cat.foods: # This fetches ALL foods!
> if food.brand = "Gourme":
> print food
If this is not feasible you can write a query by hand (almost) using SQLBuilder.
Something like this:
class MemberJoin(sqlbuilder.SQLExpression):
def __init__(self, cls, table):
self.cls = cls
self.table = table
def __sqlrepr__(self, db):
name = str(self.cls.q)
return "%s.%s_id = %s.id" % (self.table, name, name)
sr = Food.select(sqlbuilder.AND(
MemberJoin(Category, 'category_food_members')),
Food.q.brand == 'Gourme',
clauseTables=['category_food_members'])
Name 'category_food_members' can be set with intermediateTable arg to
RelatedJoin ctor.
You can also try to use various *JOIN* helper classes defined in sqlbuilder.py.
HTH,
Max Ischenko.
http://maxischenko.in.ua
Custom software development services
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss