Rename NocoDB M2M table [Mar 11]

:raising_hand_man: Mara Rafferty asked

Hi friends! Newbie here, super excited about what you all have built. I think it’s going to be a game changer for me, my colleagues, and other grassroots organizers who need easily accessible tools like this in their stacks.

I have a couple of questions about how nocodb handles linking tables for many to many relationships. tl;dr: a.) Can one a user give meaningful names to linking tables created through nocodb, or, b.) can a user use nocodb to interpolate linking tables, and use those many to many relationships (in table views, etc.)? I tried to write up a detailed problem description with screenshots here. NocoDB - Relationships and Databases - Google Docs

I’m relatively new to the open source community (and the software dev community in general), so if this should be an issue on github, or a tweet, or an email, or not asked here, or not asked at all, plz dont hate me! I’ll delete and repost somewhere more appropriate :slightly_smiling_face:

:man_bald: dstala replied

You can rename m2m tables.

- Open project

- Click on user icon > Themes

- Enable “Show M2M Tables”

- Hard refresh, (cmd+shift+r on mac) if additional tables are not displayed by default on project tree

:man_bald: dstala replied

:man_bald: dstala replied

You can then rename table or column name like any other table.

This will only change table/ column name alias for display on NocoDB UI. Right now, we do not have a mechanism to choose custom names in backend tables.

:man_bald: dstala replied

Q2: Is there any way that I can tell NocoDB about this relationship, and it can understand it and treat it the same way as if I’d made the tables through Nocodb? Alternatively, am I simply missing something, and I can make use of this functionality as-is? For example, how could I set up a sheet (view?) where a user could add and remove territories to an employee?

:man_bald: dstala replied

NocoDB infers relationship if you are connecting to external DBs. Additional relations can be created as you wish.

You can refer to following documentation section to create new links to existing tables

https://docs.nocodb.com/setup-and-usages/link-to-another-record

Subsequently, you can lookup/rollup to make more meaningful references to foreign tables

https://docs.nocodb.com/setup-and-usages/lookup

https://docs.nocodb.com/setup-and-usages/rollup

:man_bald: dstala replied

Q3: Suppose I have a relationship between two tables, as described in part 1.c. Can I edit the parameters of those relationships? Do I have to delete the relationship (and the ensuing data) and start again from scratch if I want to change the parameters, like the on delete behaviour?

You can reconfigure such relations from the backend utility like TablePlus or PGAdmin & then sync NocoDB

https://docs.nocodb.com/setup-and-usages/sync-schema

Such changes will be accounted as relation delete & create by NocoDB.

:raising_hand_man: Mara Rafferty replied

Thanks so much for the quick and informative responses! Really appreciate it. Re Q1 and Q3, I think that explains it well.

:raising_hand_man: Mara Rafferty replied

Re Q2, I’m still not understanding exactly. In my database (northwind), I have an m2m table called employee_territories with FK relationships to employees and territories.

It’s not clear to me how I can add a column to Employees showing the name of the territories they are associated with. Lookup dosn’t work, and LinkToAnotherRecord seems like it would create a new relationship on top of the existing one. When I try creating a new record link, if I try “has many” it tells me “relation update successful” and creates a new relation table in the db, in addition to the employee_territories one that already exists. But even with this, nothing changes in the UI and there’s no way to get the column with data I need. Am I missing something?


:raising_hand_man: Mara Rafferty replied

Happy to share a reproduceable example if it’s helpful!

:raising_hand_man: Mara Rafferty replied

Oh, and while we are on the topic (if you don’t mind), I had one more question, related to all of this. (Q4). Can relations only show Primary Keys?

Imagine if, in the case I asked about in Q1, we add another column in Territories, Abbreviation.

Would it ever be possible to select which field from Territories I’m going to show in the Users table in my linked field? Could I have different columns in the user tables show different fields from Territories? Happy to elaborate more if it’s helpful.

image0
image1

:man_bald: dstala replied

Q2: Adding a record, please see if the workflow captured here helps

Workflow with Launchnotes and localhost

:raising_hand_man: Mara Rafferty replied

Thanks dstala@discord ! I really appreciate it. I think maybe my question wasn’t exactly clear. I was wondering how/if I can switch between displaying the Territory Name, versus the Territory Abbreviation, in the Users table.

:man_bald: dstala replied

To use a different field, you will have to set it as ‘Primary value’

Click on drop down menu for the column you wish to reconfigure, and select it as ‘Primary Value’

:raising_hand_man: Mara Rafferty replied

^got it. Okay! So it can only show the primary value.

:man_bald: dstala replied

after configuring abbreviation as primary value

:raising_hand_man: Mara Rafferty replied

Perf. Is it on the roadmap / horizon / is it a feature I can request (and eventually possibly help with) to enable a select of a different (non PK) column from a linked table? (And if we went down that road, maybe be able to add some more complex criteria like WHERE clauses, etc.)

:man_bald: dstala replied

Primary value can be any field. Not just PK.

> (And if we went down that road, maybe be able to add some more complex criteria like WHERE clauses, etc.)

You can go ahead & request for a feature here. Do let us know use case that you are considering for the associated feature request.

:raising_hand_man: Mara Rafferty replied

Got it got it! Thanks. Will do :slightly_smiling_face:

Autogenerated from discord


Join NocoDB’s community

DiscordTwitterRedditDocs