This solution for me is not good. Ok in this case work but virtual field
allows only simple operation on the single filed of a table. I want class
with function where i can use cicle and where i can use another dal
object..This is present for all frameworks java-ruiby!!!!!!!!!!!!!!! for
exmpale
Class Person extend Model
string name,
int age ecc..
function calculateNationOfPerson(id){
Nation nation=new Nation('all')
return nation.find_nation_of_person(id)
}
}
Don't analyse the exact syntax is only a exmpale
So if there is any possibility to create a class with function where you
can use also the other tables? Only solution that I have find is to create
a file module that have the name of the table and where i put all
function...This is not a good solution but i see only this!
In Java-Ruby the model class are a rapresentation of the object database so
you can use the model class for the logic for exmpale
http://guides.rubyonrails.org/active_record_basics.html, implment function
and use this in the controller. So I see the class in web2py but don't
class that represent the model so I think is impossibile!Put all logic in
controller? Create module with many functions??
On Sunday, 6 December 2015 00:03:47 UTC+1, Anthony wrote:
> Also, note that virtual fields (both the old style you have shown below
> and the new style Field.Virtual) are designed to calculate values based on
> other fields in the record. This happens at the time the records from the
> database are parsed into a Rows object, so you cannot use these for
> updating records by calling them at some later point. Instead, for this
> purpose, you would have to use Field.Method, or if you want to use the old
> style virtual fields, you would have to define the methods as "lazy" (as
> described in the documentation). Field.Method and lazy virtual fields were
> not really designed with this use in mind, but I suppose they can be used
> this way. Here's an example:
>
> db.define_table('mytable',
> ...,
> Field.Method('change_name', lambda r, nome: r.mytable.update_record(
> nome=nome)))
>
> db.mytable(1).change_name(nome='Alessio')
>
> Anyway, there are other ways to handle such things without resorting to
> virtual fields or classes -- for example, just writing simple functions.
>
> Anthony
>
> On Saturday, December 5, 2015 at 5:24:28 PM UTC-5, Anthony wrote:
>>
>> On Saturday, December 5, 2015 at 11:37:01 AM UTC-5, Alessio Varalta wrote:
>>>
>>> Hi, I have a problem..I have controller with too much code..So I want to
>>> use the logic of Java or Ruby. Have a class that represent the object of my
>>> database and implement function in this class and use this class in the
>>> Controller. The problem is that I try the VirtualField a part of web2py
>>> guide
>>>
>>> in db file I create
>>> class Layer_scheda(object):
>>> def change_name(self,nome):
>>> self.nome=nome
>>> self.update.update_record()
>>>
>>
>> It would just be self.update_record(), not self.update.update_record().
>>
>>
>>> after in my Controller i try
>>>
>>> order_item.change_name
>>> or order_item.change_name() but I have problem change_name is not
>>> defined
>>>
>>
>> What is order_item?
>>
>> 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.