Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

More about slave tables

We have been introduced to Slave tables.

Special types of masters

The master of a slave table can be something else than a database row. For example

If the master instance is not a subclass of lino.core.fields.TableRow, it must be JSON serializable.

Slave tables with remote master

The master_key of a slave table can be a remote field.

digraph foo  {
     A -> B
     B -> C
}

When you have three models A, B and C with A.b being a pointer to B and B.c being a pointer to C, then you can design a table CsByA which shows the C instances of a given A instance by saying:

class CsByA(Cs):
    master_key = "c__b"

For example lino_xl.lib.courses.ActivitiesByTopic shows all activities about a given topic. But an activity has no foreign key topic, so you cannot say master_key = 'topic'. But a course does know its topic indirectly because it knows its activity line, and the activity line knows its topic. So you can specify a remote field:

class ActivitiesByTopic(Courses):
    master_key = 'line__topic'

    allow_create = False

A slave table with a remote master should have allow_create set to False because we cannot set a line for a new course.

Other examples