Some have gone so far to say "premature optimization is the root of all evil". I'm not quite in that camp but I do believe optimizations can and should generally wait. And for exact the reason exhibited here: they can make simple things complicated and hard to troubleshoot/fix.
I think the "load all models on every request" issue is a little overblown. I think you need 50+ tables before it becomes perceptible to end-users. On Monday, June 4, 2012 12:23:59 PM UTC-7, anonymouse wrote: > > Aw crap. And I thought I had tried that. > > setting ajax=True does indeed work... I'm guessing that it's because it > creates a separate request whereas load without ajax uses the current value > of request.controller to decide which models to execute. > > Anyway, problem solved. Thanks pbreit! > > Also, why, if I may ask, do you advise against conditional models or > 'premature optimization' as you put it? I guess there's the argument "if it > ain't broke, don't fix it". > > The thing is I do some database queries within the conditional models file > (I omitted this in my example) which I don't think should run on every page > load, especially since this particular database is accessed by several > applications. Perhaps its still premature (the db traffic is low for now... > but that db is brand new and apps haven't been modified to use it as > opposed to LDAP). > > On Monday, 4 June 2012 14:13:24 UTC-5, pbreit wrote: >> >> Hmmm...I would have expected a LOAD(...ajax=True) to trigger conditional >> models properly. >> >> Not the answer you're looking for but I very strongly advise against >> premature optimization (ie, conditional models). >> >> >> On Monday, June 4, 2012 12:01:17 PM UTC-7, anonymouse wrote: >>> >>> Hi all, >>> >>> I'm having an issue trying to load a component that relies on >>> conditionally loaded models. >>> >>> It appears that either the conditional model file is not >>> executed/evaluated using the LOAD function. >>> >>> The following files are relevant to this issue: >>> >>> models/people/personnel.py >>> controllers/people.py >>> controllers/contact.py >>> views/contact/index.html >>> views/people/index.html >>> >>> >>> The quick solution would clearly be to take the conditional model out of >>> "people" so that it is available to the "contact" controller, but I was >>> wondering if there were any another solutions which allow the "people" >>> model file to still be executed conditionally. >>> >>> Perhaps I would be better off putting the model in modules and having >>> the model/personnel.py file import the table definition from modules, and >>> add another import statement to the "contact" controller and any other >>> controllers outside of people that use personnel data (though at present, >>> contact is the ONLY one)? >>> >>> I would think that LOAD would execute the conditional model but perhaps >>> there is a good reason it does not? I could just be using components/LOAD >>> completely wrong, but if not then maybe this is a good candidate for a >>> feature request? >>> >>> If anyone can shed some light on this issue, please, shed away! >>> >>> Below are the parts my app that are relevant: >>> >>> ### Models: models/people/personnel.py >>> db.define_table('people', >>> Field(...) # Defines name, position, user-id -- this is NOT meant for >>> any sort of access control, just a list of people in our institution >>> ... >>> ) >>> >>> >>> ### I have two controllers: >>> # controller - people.py >>> def index(): >>> if request.args(0): >>> people = db(db.people.positition == request.args(0)).select() >>> else: >>> people = db(db.people).select() >>> return dict(people=people) >>> >>> # contact.py >>> def index(): >>> ... build contact form, do form validation, etc ... >>> return dict(form=form) >>> >>> # and my contact view >>> # views/contact/index.html contains this LOAD statement: >>> {{ = LOAD('people','index',args=['faculty']) }} >>> >>> When I attempt to view the page /app/contact/index >>> >>> I get the error: >>> KeyError: people >>> >>> The error is of course generated in the 2nd line of the people.py index >>> function. >>> >>> When I attempt to view /app/people/index everything works perfectly. >>> >>> Can I use LOAD with conditional models? >>> >>