문제

Goodmorning, I've a DB with three tables :

db.define_table('person',
            Field('name', length=100),
            Field('dob', length=10),
            Field('address', 'text', length=255),
            Field('countryname', length=3),
            Field('statename', length=100),
            )

db.define_table('opslist',
            Field('opid', length=10),
            Field('dop', length=10),
            Field('type_operation', length=25),
            )

db.define_table('cardlist',
            Field('opid', db.opslist),
            Field('name', db.person),
            Field('countryname', length=3, required=True),
            Field('statename', length=100, required=True),
            Field('zip', length=5, required=False),
            )

I would insert by code, means not using a sqlform or a form, some data into ... e.g.: If i have all the values insertable into cardlist table the operation must give me the ability to fill automatically the related record (creating new if not present) into the other tables. This because it's a relational db with foreign keys ...

Is this possible with web2py using the DAL ? or do i have to write my raw sql command ?

Thank You All

도움이 되었습니까?

해결책

Just use the insert method. It returns the ID of the newly created record, which you can use to insert into the reference fields:

person = db.person.insert(name=..., dob=..., ...)
opslist = db.opslist.insert(opid=..., dop=..., ...)
db.cardlist.insert(opid=opslist, name=person, ...)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top