On Monday, November 2, 2015 at 9:50:34 AM UTC-5, Carlos Cesar Caballero 
wrote:
>
> ok, now is not so clean, the "functions" are before the "variables" 
> declarations,
>

In weppy, you have this (note the need for the @virtualfield decorator):

class Review:
    author = Field()
    value = Field('int')
    valuea = Field('int')
    valueb = Field('int')
    place = Field('reference place')

    @virtualfield('value')
    def get_average(row):
        # all the code...
        # ...
        return value

In web2py, you can do this:

db.define_table('review',
   Field('author'),
   Field('valuea', 'int'),
   Field('valueb', 'int'),
   Field('valuec', 'int'),
   Field('place','reference place'))

def get_review_average(row):
    # all the code...
    # ...
    return value
db.review.value = Field.Virtual('value', get_review_average),

Same number of lines in the same order. I agree, though, that the first 
approach looks a little nicer (mainly because the virtual field method is 
namespaced inside the class), but it's not a dramatic difference (and it 
would be easy to write a simple decorator to add the virtual field to the 
table in order to eliminate that last line). Also, the second approach 
makes it easier to share the virtual field function across multiple tables 
if needed (without having to worry about multiple inheritance, etc.).

we could add some validations, and we get functions code, fields 
> declarations, and validation code, in that order
>

As noted above, you can put these in any order you want in web2py. I also 
find it easier to keep all the attributes (e.g., validators, represent 
function, etc.) of a given field together, but I suppose that could vary 
depending on the situation.

I agree that table inheritance is more flexible with the class based 
method. You can do some basic inheritance with web2py, but it becomes 
trickier if you need to override specific fields or copy attributes other 
than fields. I suppose this could be improved in web2py even without using 
classes -- perhaps it has not been done because there hasn't been much 
demand.
 

> About the objects, if we could have real orm functionality, we could do 
> things like: 
>
object = db.mytable[id]
> object.name = "the name"
> object.save()
>
>
I don't think we need an ORM for that:

row = db.mytable[id]
row.name = 'the name'
row.update_record()

The non persistent variables is other thing, in some cases we need to use 
> non persistent variables, like flags, with the virtual or method fields, we 
> can define non persistent values, but we can't edit them.
>

First, you can simply do:

row = db.mytable(id)
row.my_non_persistent_variable = 'some value'

Second, you *can* update virtual field values:

 row.my_virtual_field = 'new value'

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.

Reply via email to