Skip to content

Instantly share code, notes, and snippets.

@jibran
Last active January 29, 2019 05:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jibran/7afa1a6d90387e5ff674b6705b71af9b to your computer and use it in GitHub Desktop.
Save jibran/7afa1a6d90387e5ff674b6705b71af9b to your computer and use it in GitHub Desktop.
Basefield scenarios in Drupal 8

There are 18 kind of different scenarios for basefield:

  1. non-translatable and non-revisionable entity with basefield with cardnality 1. One DB table: base Field column(s) in base table
  2. non-translatable and non-revisionable entity with basefield with cardnality greater than 1. Two DB tables: base, field table Field column(s) in field table
  3. translatable and non-revisionable entity with basefield with cardnality 1. Two DB tables: base, data Field column(s) in data table
    • non-translatable basefield.
    • translatable basefield.
  4. translatable and non-revisionable entity with basefield with cardnality greater than 1. Three DB tables: base, data, field table Field column(s) in field table
    • non-translatable basefield.
    • translatable basefield.
  5. non-translatable and revisionable entity with basefield with cardnality 1. Two DB tables: base, revision
    • non-revisionable basefield. Field column(s) in base table
    • revisionable basefield. Field column(s) in base table and revision table
  6. non-translatable and revisionable entity with basefield with cardnality greater than 1.
    • non-revisionable basefield. Threes DB tables: base, revision, field table Field column(s) in field table
    • revisionable basefield. Four DB tables: base, revision, field table, field revision table Field column(s) in field table and field revision table
  7. translatable and revisionable entity with basefield with cardnality 1. Four DB tables: base, data, revision, data revision
    • non-translatable and non-revisionable basefield Field column(s) in data table
    • translatable and non-revisionable basefield Field column(s) in data table
    • non-translatable and revisionable basefield Field column(s) in data table and revision table
    • translatable and revisionable basefield Field column(s) in data table and revision table
  8. translatable and revisionable entity with basefield with cardnality greater than 1.
    • non-translatable and non-revisionable basefield Five DB tables: base, data, revision, data revision, field table Field column(s) in field table
    • translatable and non-revisionable basefield Five DB tables: base, data, revision, data revision, field table Field column(s) in field table
    • non-translatable and revisionable basefield Six DB tables: base, data, revision, data revision, field table, field revision table Field column(s) in field table and field revision table
    • translatable and revisionable basefield Six DB tables: base, data, revision, data revision, field table, field revision table Field column(s) in field table and field revision table

And now multiply 18 with 3 because we support three databases driver in core.

@jibran
Copy link
Author

jibran commented Jul 29, 2016

This is not it a basefield can also have more then one DB column as well.

@chx
Copy link

chx commented Jul 29, 2016

Although I started a spreadsheet it might not be necessary. Here are some thoughts.

Our fields do not have custom storage, those are not stored by this system so let's disregard that option. In order to simplify further, let's disregard keys (id, vid) and revision metadata (log). These are not interesting.

If we seek to answer the "are field columns in table X" the first question to answer is cardinality: if cardinality is not 1 then the field data goes into a dedicated table and if both the field and the entity is revisionable then there will be a dedicated field revision table for the revisions. Configurable fields behave the same as these not-1-cardinality base fields. With one exception: configurable fields are always revisionable even if the entity is not and this is why you need to check both the entity and field definitions before presuming the existence of a revision table.

Now, base fields with cardinality 1 share tables.

There can be as many as four shared tables.

If the question is: are field columns in the

  1. Revision data table? The entity is translatable, the entity is revisionable, the field is revisionable.
  2. Revision table? The entity is not translatable, is revisionable and the field is revisionable.
  3. Data table? If the entity is translatable.
  4. Base table? If the entity is not translatable.

Possible combinations:

  1. Field columns are in base and possibly in revision
  2. Field columns are in data and possibly in revision data.

No other combinations are legit.

The value of the columns are (obviously) current revision in data or base, revision data in revision or revision data table.

@jibran
Copy link
Author

jibran commented Jul 29, 2016

Yup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment