Hi

Advertisements can be published in different magazines. I represent
this with the following tables:

db.define_table("magazine",
  SQLField("owner",db.auth_user, writable=False, readable=False))

db.define_table("advertisement",
  SQLField("owner",db.auth_user,writable=False, readable=False),
  SQLField("description", "text", notnull=True, label = T
("Description"),
  SQLField("mag_id", db.magazine,writable=False, readable=False))

db.define_table("published",
    SQLField("advertisement_id", db.advertisement),
    SQLField("mag_id", db.magazine),
    SQLField("url", "string",length=2048, notnull=True,
default=None))


What I need is a query that, given a user, for each of his
advertisement gives me the magazines it is printed on.
Since on GAE I cannot have joins I simulated this by doing the
following:

 query = (db.advertisement.id>0)&(db.advertisement.owner ==
auth.user.id)
 links = db(query).select(orderby=db.advertisement.posted_on)

# links now contains all the advertisements for the logged-in user

 for b in links:
        query=(db.published.id>0) & (db.published.advertisement_id ==
b.id)
        res = db(query).select()
        for a in res:
            print a.mag_id  # prints the id of the magazine the
advertisement is published in

Is there a better way of doing this in GAE? Performance is one of my
main concerns here.

thanks
-M


-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to