Bolt.tips

Finding all rows in the database related to a Record

Under the hood, Bolt uses the Doctrine ORM to abstract database storage. This means that a Record in, for example, the Pages ContentType will behave as a single Entity in Bolt, but in the database, its data is persisted in a few different tables.

Sometimes though, you might want to be able to see all database rows that are linked to one Record. If so, you can use the following queries to do this:

-- The row in the 'main' bolt_content table
SELECT * FROM bolt_content WHERE id = 67;

-- The linked fields in bolt_fields
SELECT * FROM bolt_field WHERE content_id = 67;

-- The localised values of those fields
select * from bolt_field_translation where translatable_id in (SELECT id FROM bolt_field WHERE content_id = 67);

-- The linked taxonomies from `bolt_taxonomies`
SELECT * FROM bolt_taxonomy WHERE id IN (SELECT taxonomy_id FROM bolt_taxonomy_content WHERE content_id = 67);

-- The linked relationships from `bolt_relations`
SELECT * FROM bolt_relation WHERE to_content_id = 67 or from_content_id = 67;

Obviously, replace the 67 with the ID of the Record you’re looking for.

Sql Database Mysql Doctrine

Permalink - Written by Bob on March 31, 2021.

« Outputting the total number of Records for a contentType - Renaming ContentTypes »