DAL implementation nof the Table-per-type inheritance model?

36 views
Skip to first unread message

BigBaaadBob

unread,
Oct 17, 2020, 7:23:00 PM10/17/20
to web2py-users
It's hard to believe that I was talking about this in 2013, but here it is again!

I'm wondering if you can directly implement the Table-per-type or Shared-primary-key method of inheritance in the DAL?

subclass-gradstu-scheme.gif

The standard DAL inheritance method (including a table as a field) is a Table-per-concrete approach that has pros and cons. In particular for me, it is harder to deal with the common stuff (the stuff in the superclass) with the standard DAL method.  In many cases I never need to refer to the subclass specifics.

The best I have been able to do is something like the below. There is a lot of common stuff in the duration table (and, btw, the duration can be overridden and isn't necessarily the difference of the start and stop values in the subclasses). Depending on how the time is tracked, there are different algorithms used to compute a duration, for  example subtracting two datetimes or subtracting two floats (representing hours).

db.define_table(
    'duration',
    # Common stuff
    Field('duration','decimal(10,2)',notnull=True),
)

db.define_table(
    'datetime_duration',
    Field('superclass','reference duration',unique=True,notnull=True),
    Field('start','datetime',notnull=True),
    Field('stop','datetime',notnull=True),
)

db.define_table(
    'hour_duration',
    Field('superclass','reference duration',unique=True,notnull=True),
    Field('start','decimal(10,2)',notnull=True),
    Field('stop','decimal(10,2)',notnull=True),
)


valq...@gmail.com

unread,
Oct 23, 2020, 1:25:23 AM10/23/20
to web2py-users

Shared pk works just fine:


db.define_table(
    'datetime_duration',
    Field('superclass','reference duration') ,
    primarykey = ['superclass']
)
воскресенье, 18 октября 2020 г. в 02:23:00 UTC+3, BigBaaadBob:

valq...@gmail.com

unread,
Oct 23, 2020, 1:32:16 AM10/23/20
to web2py-users
Also I fixed some bugs https://github.com/web2py/pydal/issues/548

пятница, 23 октября 2020 г. в 08:25:23 UTC+3, valq...@gmail.com:

valq...@gmail.com

unread,
Oct 23, 2020, 1:38:14 AM10/23/20
to web2py-users
Also maybe useful https://github.com/web2py/pydal/issues/627

пятница, 23 октября 2020 г. в 08:32:16 UTC+3, valq...@gmail.com:
Reply all
Reply to author
Forward
0 new messages