The new database sub tables on existing databases schemas

Is it necessary to prefix sub tables with main table names only if you use custom databases, or it is also necessary if you use Database Manager?

I don’t think I ever use this naming convention. Eg if I had these tables:
customers > orders > order items
… if I understand correctly, I would have to have to name the last table something like orders_orderitems. If I wanted to create a query with orders nested within customers, does that mean I would have to name the orders table, customers_orders (and therefore rename the last table customers_orders_orderitems)?

I’ve probably misunderstood how the new feature works. and perhaps it’s not in fact necessary to adopt this naming convention.

(I don’t think I ever think about ‘sub tables’ - perhaps ‘child tables’ but it’s a matter of context.)

1 Like

You seem to have already the right naming convention which is pretty much standard.

So directly related sub tables like in your case order_items are prefixed with the main table “order”
Plurals or singulars are considered so a match should be found.

So you are good to go :slight_smile:

That’s good as that was one slight problem. Does there have to be a separator - eg would it have to be order_items or would be orderitems work too? (I have projects with both forms - due to inconsistency on my part).

Perhaps there is still a problem, using my example, in that I would need my orders table to be customer_orders (which I would never normally use), and therefore my orderitems table would be customer_order_orderitems.

Anyway, I’m sure it will make more sense when I actually try out the new feature (when the PHP version is available). Also, it’s not as it it’s a critical feature - just a useful option if appropriate.

Underscores are ignored as well. And you prefixes tables really just to identify direct relations.

So you don’t have to prefix orders with customer. Only if you really want to identify that orders exist only under customers.

You can already see the existing relations and how the matching is done in the database manager.

The visualization and creating of sub tables is activated if you have experimental options on.

Only doing nested queries is currently only supported for NodeJS but soon php will follow.

1 Like

How can we convert existing tables to sub-tables?

e.g.:
books: id
book_pages: id; reference book_id

The naming convention is according to Laravel’s convention (edit: just the reference naming)

I’m pretty lost what to do, despite the feature looking exciting!

Edit: I probably didn’t set book_id as reference, but rather an integer

Edit 2: it’s simply not working, if I create a subtable, run the migrations, the subtable disappears from the DB manager and acts like the old view instead

Good point - it might be the reference naming indeed. Will make sure the singular form is used, so book_id indeed when coming from books

A post was split to a new topic: Sub Tables on more than one level

This has been fixed in Wappler 4.7.2