Hello all, I've been thinking about implementing a module that takes a DAL table definition and generates a class object from that definition. The purpose of this is to use those automatically generated classes in the controllers instead of accessing the DAL directly. Eg: Creating an instance of that class could make an insertion in the db transparently; setting attributes on that instance triggers db updates, etc.. One important feature is that every table Row is mapped to an instance of some class and this layer is completely opaque, i.e. it can't expose any Rows/Row/Field objects to the client.
A more concrete example of whats being pursued: ----------------- db.define_table( "Person", Field('name') ) db.define_table( "Dog", Field("name"), Field("Owner",db.Person) ) *createClass*(db.Person) *createClass*(db.Dog) #and now you can do: p = Person("John") #selects person with name="John", possibly throwing exception or creating such a record (have to weigh the pros and cons) johns_dogs = p.dog_list #johns_dogs is a *list* of *Dog* instances johns_dogs[0].name #returns name of one of the john's dogs. johns_dogs[0].name = "new name" #updates this dogs name in db ----------------- I've had some success a this, namely, made a function that takes a Rows object and returns a list of Storage instances where each storage has the same attributes as the corresponding Row fields and, whenever the value of a Row's Field is a Sql.Set, it *.selects()* it and continues recursively until everything is converted into a big tree of Storage instances. This is where I ask for some help. Ideally I don't want to convert every Row into a Storage, I'd like a Row of table *Product* (e.g.) to be converted into an instance of class *Product* (which was automatically generated when table Product was defined). Yet, I do not know of *an easy way to get the Table from which a specific Row came from. Is it possible without major hacks in the DAL?* Also, since you're at it, what do you think about this? My motivation is that it gets tiring to be defining helper functions to make the controller code simpler and then be constantly updating those helper functions whenever the model changes. Thanks a lot in advance, Tiago -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.