Dear Anthony, Thank you very much for this very clear answer.
Archibald On 24 oct, 16:02, Anthony <abasta...@gmail.com> wrote: > On Monday, October 24, 2011 9:33:33 AM UTC-4, Archibald Linx wrote: > > > Dear web2py users, > > > I have some questions about the book : > > > 1) There is a typo here : > >http://www.web2py.com/book/default/chapter/10#Auto-completion > > It should be "if not request.vars.month:" and not "it not > > request.vars.month:" > > > 2) On page 69, what do you mean by "private" ? > > " Class atributes, methods, and operators starting with a double > > underscore are usually intended to be private" > > Look at the "Designing for inheritance" section > here:http://www.python.org/dev/peps/pep-0008/. > > > > > 3) On page 105, there is the following line : > > "images = db().select(db.image.ALL, orderby=db.image.title)" > > > On page 108, there is the following line : > > "comments = db(db.comment.image_id==image.id).select()" > > > When is the query written inside the brackets of db() and when is it > > written inside the brackets of select() ? > > The content of the first select() is not a query -- it is just specifying > the fields to select, as well as an orderby. However, when you specify > fields to select in the select(), specifying a query in the db() is optional > -- it defaults to a query for all the records in the table. In the second > case, because select() is empty, it defaults to selecting all the fields in > the queried table (i.e., in db.comment). Basically, as long as there's > something in the select(), you can leave the query empty, and it defaults to > all the records in the table, and if there's a query, you can leave select() > empty, and it defaults to all the fields in the table. This is explained > here:http://web2py.com/book/default/chapter/06#select > > > > > 4) On page 108, there is this line : > > "db.comment.image_id.default = image.id" > > > What does "default" do ? Couldn't it just be "db.comment.image_id = > > image.id" ? > > Fields can have default values, and you can assign, access, and update them > via the field's 'default' attribute. Often initially the default is > specified when the field is first defined: > > db.define_table('mytable', Field('myfield', default='my default value')) > > This can then be accessed and changed via db.mytable.myfield.default. You > can also make the initial assignment via db.mytable.myfield.default. > > You don't want to do db.comment.image_id = image.id because > db.comment.image_id is itself a Field object, and this assignment would > replace the entire Field object with image.id. > > Anthony