On Sunday, July 9, 2017 at 3:10:47 PM UTC-4, Anthony wrote:
>
> On Saturday, July 8, 2017 at 4:54:51 PM UTC-4, Filipe Reis wrote:
>>
>> I was trying to implement this but I can't understand one thing.
>>
>> In this example:
>>
>> db.define_table('abonent', Field('a'))
>> db.define_table('person', db.abonet, Field('b')) # has a,b
>> db.define_table('company', db.abonet, Field('c')) # has a,c
>>
>>
>> You would create many persons and companies, how would you select them
>> all from the abonent? Since I tried it and the abonent table will be
>> empty...
>>
>> For example:
>>
>> some table 1------n abonent , and that abonent is either a person or a
>> company.
>>
>
> The above code simply creates db.person and db.company tables that have
> the same fields as the db.abonent table. However, records in the three
> tables are separate -- a record in the db.person table does not also appear
> in the db.abonet table. If you want a single collection of records that can
> have different types, you should probably just have a single table with
> some kind of "type" field.
>
And note, the above is akin to Django's abstract base class
<https://docs.djangoproject.com/en/1.11/topics/db/models/#abstract-base-classes>
approach to model inheritance.
Perhaps you are more interested in the multi-table inheritance
<https://docs.djangoproject.com/en/1.11/topics/db/models/#multi-table-inheritance>
approach. With this approach, Django uses class inheritance to
automatically generate one-to-one relations between tables. With the web2py
DAL, you would simply do this explicitly by creating a reference field from
the child table to the parent.
Anthony
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.