Slave tables

A table is called a slave table when it "depends" on a master.

For example the BooksByAuthor table in Introduction to data views shows the books written by a given author. Or the ChoicesByQuestion table in The Lino Polls tutorial shows the choices for a given question (its master). Other examples of slave tables are used in A Local Exchange Trade System and Table summaries.

A slave table cannot render if we don't define the master. You cannot ask Lino to render the BooksByAuthor table if you don't specify for which author you want it.

Slave tables are most often used as elements of a detail layout. In this case Lino renders them in a slave panel widget, and the current record is the master.

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 shows all courses about a given topic. But a course has no FK topic, so you cannot say master_key = 'topic'. But a course does know its topic indirectll because it knows it's course series, and the course series 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