テーブル継承

□未翻訳

□翻訳中

■翻訳完了(細田謙二)

■レビュー(Omi Chiba)

テーブル継承

他のテーブルのすべてのフィールドを含んだテーブルを作成することが可能です。これは、他のテーブルをdefine_tableに置くだけで十分です。たとえば次のようになります。

It is possible to create a table that contains all the fields from another table. It is sufficient to pass the other table in place of a field to define_table. For example

1.

2.

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

db.define_table('doctor', db.person, Field('specialization'))

データベースに保存されないダミーテーブルを定義して、他の複数の場所で再利用することも可能です。例:

It is also possible to define a dummy table that is not stored in a database in order to reuse it in multiple other places. For example:

1.

2.

3.

4.

5.

6.

7.

signature = db.Table(db, 'signature',

Field('created_on', 'datetime', default=request.now),

Field('created_by', db.auth_user, default=auth.user_id),

Field('updated_on', 'datetime', update=request.now),

Field('updated_by', db.auth_user, update=auth.user_id))

db.define_table('payment', signature, Field('amount', 'double'))

この例は、標準のweb2py認証が有効になっていることを前提としています。

This example assumes that standard web2py authentication is enabled.