Re: Web2py ORM: Inheritance

8 views
Skip to first unread message

Massimo Di Pierro

unread,
Jan 17, 2008, 12:43:55 PM1/17/08
to Sharriff, web...@googlegroups.com
This concept does not exist in web2py but you may try

db.define_table('person',....)

fields=[db.person[key] for key in db.person.fields if key!='id']
fields.append(SQLField('company',....))

db.define_table('employee',*fields)

Let us know if it works.

On Jan 17, 2008, at 11:36 AM, Sharriff wrote:

> Yes I know that, I have used that extensively and it works, but thats
> not what I meant by subclassing(inheritance)
>
> Storm, SQLalchemy e.t.c all support this, a Storm example:
>
> 1 >>> class Person(object):
> 2 ... __storm_table__ = "person"
> 3 ... id = Int(primary=True)
> 4 ... name = Unicode()
>
>
> 1 >>> class Employee(Person):
> 2 ... __storm_table__ = "employee"
> 3 ... company_id = Int()
> 4 ... company = Reference(company_id, Company.id)
> 5 ...
> 6 ... def __init__(self, name):
> 7 ... self.name = name
>
>
>
> Employee is a subclass of "Person"
>
>
> I intend to subclass "Person" to "Parent" and "Child"
>
> Was that clear?
>
> On Jan 17, 2008 4:12 PM, Massimo Di Pierro
> <mdip...@cs.depaul.edu> wrote:
>> Not sure I understand
>>
>> db=SQLDB('....')
>>
>> parent=db.define_table('parent',SQLField
>> ('name2','string',length=20),SQLField('type2','string',lenght=20))
>>
>> then you use db.parent
>>
>> there is no need to import anything. Only SQLDB and SQLField are
>> visible in the scope.
>>
>>
>>
>> On Jan 17, 2008, at 3:48 AM, Sharriff wrote:
>>
>>> Hi Massimo, a quick question:
>>>
>>> Parent = SQLTable('parent',
>>> SQLField('name2', 'string', length = 20),
>>> SQLField('type2', 'string', length = 20)
>>> )
>>>
>>>
>>> What would be the proper "web2py" way to import SQLTable for use? I
>>> dont want to start doing things like "import gluon.sql.SQLTable",
>>> things would then be like Pylons.
>>>
>>>
>>> Thanks
>>
>>

voltron

unread,
Jan 18, 2008, 2:38:05 AM1/18/08
to web2py Web Framework
Hmm, the problem I see with this method is that changes to the
"Person" class do not propagate to the "Employee" class as in other
ORMs, which is actually one of the points of using inheritance in a
case like this.
Reply all
Reply to author
Forward
0 new messages