It does not break you simply get None.
On Saturday, 9 March 2013 10:38:57 UTC-6, jjg0 wrote:
>
> Hello again, I have another problem I've run into maybe someone can help
> with.
>
> Let's say I have a table of blog posts and all I want to do is print out
> all the titles. I'll make up a really simple example:
>
> MODEL:
>
> db.define_table('myBlog',
> Field('title'),
> Field('body', 'text'),
> Field('created_on', 'datetime', default=request.now))
>
> CONTROLLER:
>
> def index():
> titles = db(db.myBlog).select()
> return locals()
>
> INDEX VIEW:
>
> {{for title in titles:}}
> {{=title.title}}
> {{pass}}
>
> Now this works, but isn't it a waste to grab all the body and created_on
> fields if I don't plan on using them?
> I'm looking at the web2py book and it says in the select section of the
> DAL:
>
> The select command can take arguments. All unnamed arguments are
> interpreted as the names of the fields that you want to fetch. For example,
> *you can be explicit on fetching field "id" and field "name"*:
>
> >>> for row in db().select(db.person.id, db.person.name):
> print row.name
> Alex
> Bob
> Carl
>
>
> So if I am understanding this correctly, I should be able to edit the
> controller above to say:
>
>
> def index():
> titles = db().select(db.myBlog.title)
> return locals()
>
> and titles should now only contain the title fields of myBlog. So if I
> add something crazy in the view like this:
>
> VIEW:
>
> {{for title in titles:}}
> {{=title.title}}
> *{{=title.body}}*
> {{pass}}
>
> I am expecting this to break, but this works fine. Shouldn't the
> {{=title.body}} part break the view now that I am only grabbing the
> titles? Shouldn't title.body not exist?
> Why am I still able to print out the title.body, title.created_on date,
> and title.id?
> Does fetching only the title save me anything in the long run, or will
> grabbing the entire table cost the same as far as performance?
> What have I misinterpreted with the example taken from the book?
>
> Thanks
>
>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.