laravel-enso / tables

Bulma themed, VueJS powered Datatable with server-side loading and JSON template setup
https://www.laravel-enso.com/examples/table
632 stars 77 forks source link

Tables with many-to-many related entities - id conflicts #249

Closed robbykrlos closed 3 years ago

robbykrlos commented 3 years ago

This is a feature request/question.

Prerequisites

Description

Hi there,

I was wondering how would you use an enso-table to show 2 many-to-many related entities.

Let's assume I have 2 models, posts and tags. One post can have multiple tags, one tag can be used for multiple pots. I want a table that shows all posts and tags.

The issue we will ran into is the id (dtRowId), which will not be unique, therefore:

[Vue warn]: Duplicate keys detected: '123'. This may cause an update error.

We thought of simulating an unique Id for each relation but this change affects all tables(config/enso/tables.php - 'dtRowId' => 'id',) and will break the routes used for that table.

Is there a way to achieve this with enso tables or it needs to be done custom?

Thank you,

aocneanu commented 3 years ago

use a custom dtRowId. Maybe add in select a computed id like post_id-tag_id as dt_row_id and in the template use that dtRowId.

robbykrlos commented 3 years ago

use a custom dtRowId. Maybe add in select a computed id like post_id-tag_id as dt_row_id and in the template use that dtRowId.

Not completely sure that a custom dtRowId means - I'm looking at the documentation and https://docs.laravel-enso.com/backend/tables.html#template there is no local template json config to overwrite the global one.

Or, you mean to change the global configuration with a custom one (ex: "customId") and in normal tables this one will be the normal id (model.id as customId), but in my special scenario use the computed id to give uniqueness? Thanks for the fast reply.

PS / off-topic : how are you guys doing ? all good? we saw a delay in the enso releases (which you made us believe it's a monthly thing :) We hope you are all good and not affected by ongoing current global situation...

aocneanu commented 3 years ago

add in your template "dtRowId": ...., it's probably not documented.

We're all good but we're in the process of launching a new business line and we're overwhelmed, for the moment.

robbykrlos commented 3 years ago

Nice.

I'll check and update the documentation with the missing line.

Thanks!