Symmetric many-to-many relationship in Directus - many-to-many

I have two collections in Directus (data platform that provides many features including REST API over database records). There is option to set relationship between different collections.
I set many-to-many relationship between collectionA and collectionB.
Special system collection (junction table) called collectionA_collectionB was automatically created. Now I can add items from collectionB while editing collectionA items.
But same time I want to add collectionA items while editing collectionB items and I don't find way to add existing junction table. When I add many-to-many relationship between collectionB and collectionA - new junction table is created.
How can I use same junction table to achieve symmetric many-to-many relationship?

From the Directus UI you can delete the relation from CollectionA and also delete the junction table collectionA_collectionB and then create again the M2M to CollectionB but when creating, please click "Continue in Advanced Field Creation Mode" just below the "Save" button you'd like to rush to click otherwise: https://i.imgur.com/7LASmQp.png
Now, click "Relation" from the left menu and under "Corresponding Field" check the "Add M2M" to ColumnB" checkbox: https://i.imgur.com/ptb0aNr.png
If you don't want to delete what's created already (for example, lot of data in the tables already), then I think the only way is to make changes directly to the directus_* tables on the database. I don't know how to do it as I didn't have much data when I had this problem.

Related

MS Access many-to-many relationship: association table vs. multi-value lookup field(s)?

There is a classic way to create many-to-many relationship by using an association (junction) table.
Also, I am noticing that MS Access has "Allow multiple values" option in table field properties in Lookup tab. Switching this option to "Yes" allows you to point to many records in another table instead of pointing to just one. This effectively creates some form of many-to-many relationship, at least one-way many-to-many relationship. The upside of this approach is that it has zero development overhead, as it works out of the box.
Q1: So what is the catch in this second option? Why would I want to use the classic junction table and not this other approach?
Q2: Is there a way to make "allow multiple values" a true two-way M:M relationship, where I could point at multiple records in another table from either table, not just one?

Can 2 relationships have a relationship between them (Database)?

Consider the scenario between a Project, Task, and a User (ER diagram attached included):
A project can have multiple tasks and a task can be in multiple projects (thus the many-many relationship ProjectTask)
A project can have multiple users and a user can be in multiple projects (thus the many-many relationship ProjectUser)
Check the above example's ER Diagram here
Now a ProjectTask can be assigned to multiple ProjectUsers and a ProjectUser can be assigned multiple ProjectTasks, basically a TasksAssigned relationship
How will I go about storing that information in a database? Can two relationships have a relationship? If yes, is there a better way to showcase this scenario? And if no, how do you show this relationship?
You can have a three-way relationship, in your case:
user
project
task
You probably want to guarantee that the user and task have the same project. That can be handled by declaring composite foreign keys to the projectTasks and projectUsers tables. The structure guarantees that the user and task are in the same project (because it is explicitly mentioned in the row in this table).

Multiple Tables Sharing Info to one

I have 4 tables, "Player", "Crafting", "Battling", "Gathering".
I made a relationship rule for Crafting, Battling and Gathering to share information to the Player table.
The problem is that when I go to the player table it makes me choose which other table's information to display instead of showing all 3.
How can I make a relationship so that I can view all three other tables from the player table?
It's impossible and you don't need this. You already have all relationships you need. Just create a form based on Player table with 3 subforms and link them on form, no additional code required in simple case.
Also I would recommend do not use username as primary key, use Autonumber data type instead.

MySQL many-to-many relationship table usage

I have three tables: Resumes, Orgs, and Resume2Org. Basically, Resume2Org is my many-to-many relationship table linking Resumes.resume_id to Orgs.org_id (so it only has those two keys in that table).
My question is, is it okay to use that many-to-many relationship table to store other data? My use case: the database is part of a system to sift through incoming resumes. But I've been asked to implement a "marked as read" feature so we can easily get the list of resumes we haven't looked at yet. But since a resume can belong to many different orgs, we only want to mark a resume as read for the org the user/viewer belongs to. I thought, hey, having that flag in Resume2Org would be perfect. Is this a smart approach, or should I create a new table specifically for "marked as read"? All the examples I've seen about many-to-many relationship tables is that those tables are used just for that... linking two tables.
Yes it is okey to have additional fields in a many-to-many table. I think it is the right way to do in your case as you don't need to join additional tables and you save spaces.
I was in a very similar situation last week and I added additional field for that.

Linq2Sql: linking tables without relationships

I'm new to Linq2Sql and to learn it I'm trying to setup reports using Linq2Sql against the FogBugz tables. But, since the FogBugz tables don't have any true Foreign Key relationships, LinqToSql isn't finding the relationships and I can't figure out how to create them through the Designer. So, is there a way to do this manually? If I do it manually and then later decide to add another table, will everything I did be overwritten?
You can add relationships (aka Associations) in the SQL2LINQ designer by right clicking the white space in the designer, choose Add -> Association.
Choose your parent and child tables (classes), then link the properties on the tables accordingly using the grid that appears below the dropdowns for parent and child classes