Hi Mehdi, traversing your resource tree does not necessarily mean running any queries. In your example, it wouldn't have to run any queries at all. Basically, it is there to bring you to the view and possibly gather some information on the way. For example (simplified and certainly not working):
class TopContext(object): def __init__(self, request): self.request = request def __getitem__(self, entity_name): if "customers" == entity_name: return CustomerContext(self.request) class CustomersContext(object): def __init__(self, request): self.request = request def get_data(self): # run the select and collect the data ... def __getitem__(self, ent_id): if ent_id.isdigit(): return OneCustomerContext(self.request) class OneCustomerContext(object): def __init__(self, request): self.request = request def get_data(self): # run the select and collect the data ... Now, when pyramid traverses the resource tree, it only uses constructors and __getitem__, so if there are no queries in there, they are not run. And you usually do not need them. If it was up to me, I would not define OrderContext. The traversal would get me to OneCustomerContext, and *order* would be the view name (parameter name of view_config). -- Petr On Fri, Aug 28, 2015 at 9:54 AM, Mehdi <mese1...@gmail.com> wrote: > Hi > Let's get straight to my question: > Consider this url: *http://mysite.com/customers/137/orders?year=2015&month=5 > <http://mysite.com/customers/137/orders?year=2015&month=5>* > Now in pyramid traversal mechanism, how many queries will be run against > database? > I guess it would be three: > 1. */customers* : select * from customers > 2. */customers/137* : select * from customers > where id = 137 > 3. */customers/137/**orders?year=2015&month=5: *select * from orders where > customer_id = 137 and year=:year and month=:month > > If so is there anyway to reduce the db queries down to one last query? > Thanks. > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pylons-discuss+unsubscr...@googlegroups.com. > To post to this group, send email to pylons-discuss@googlegroups.com. > Visit this group at http://groups.google.com/group/pylons-discuss. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.