(more) problems with inheritance

Lorenzo Gil Sanchez <[email protected]> Tue, 17 Aug 2004 17:16:16 +0200
Newsgroups gmane.comp.python.modeling
Message-ID <[email protected]>
Hi again :-)

Using the dynamic module (from CVS) I was able to create the Python
classes of my model, which uses inheritance:

My model has two entities: Person and Customer, which inherits from
Person.

My problem now is related to fetches. I have two instances on my
EditingContext: a person and a customer:

    ec = EditingContext()
    p = Person()
    p.setName('Erny')
    ec.insert(p)
    print p

    c = Customer()
    c.setName('Lorenzo')
    c.setPhone('93923924')
    print c

Now, how do I get all the person in my editing context?

    query = ec.fetch('Person', isDeep=1)
    print len(query)
    1

As you can see I'm getting one object when I should been getting two
since the Customer is-a Person

Am I doing something wrong or I just hit a bug?

I'll attach the whole code so everybody can test it.

Regards

Lorenzo
model_person.py (application/x-python, 1.3 KB)
from Modeling import dynamic
from Modeling.PyModel import *
from Modeling.ModelSet import defaultModelSet

Attribute.defaults['usedForLocking']=1
AString.defaults['externalType']='TEXT'
AString.defaults['width'] = 0
AString.defaults['usedForLocking']=1

Association.defaults['delete']=['nullify', 'nullify']

Entity.defaults['properties'] = [
  APrimaryKey('id', isClassProperty=0, isRequired=1, doc='PK')
]

_connDict = {'database': 'people.sqlite'}
model = Model('Person', adaptorName='SQLite', connDict=_connDict,
              version='0.1')

model.entities = [
    Entity('Person',
           properties = [AString('name'), AString('surname')],
           ),
    Entity('Customer',
           properties = [AString('phone')],
           parent='Person',
           )
    ]

model.build()

defaultModelSet().addModel(model.component)

dynamic.build_with_metaclass(model.component, define_properties=1)

if __name__ == '__main__':
    from Modeling.EditingContext import EditingContext
    from Person.Person import Person
    from Person.Customer import Customer

    ec = EditingContext()
    p = Person()
    p.setName('Erny')
    ec.insert(p)
    print p

    c = Customer()
    c.setName('Lorenzo')
    c.setPhone('93923924')
    print c

    query = ec.fetch('Person', isDeep=1)
    print len(query)