nocobase/nocobase

one-to-one relation not respected

jakob1379 opened this issue · 3 comments

Describe the bug

In the NocoBase EDMS system, there appears to be an inconsistency in the relationship behavior. The Documents collection is expected to have a one-to-one relationship with the Versions collection via the Active Version field. However, I am able to associate multiple Versions with a single Document which contradicts the one-to-one relationship and effectively creates a one-to-many relationship from the Documents side. This allows multiple active versions of a document, which should not be possible.

Version

NocoBase v0.20.0-alpha.16 running in Docker.

How To Reproduce

Steps to reproduce the behavior:

  1. Go to 'Graphical interface' under 'Data source manager'.
  2. Create a new document in the Documents collection.
  3. Add multiple versions in the Versions collection and associate them with the single document created in step 2.
  4. Observe that the system allows multiple active versions to be linked to a single document.

Expected behavior

The expected behavior is that only one version should be active and associated with a document at any given time, respecting the one-to-one relationship.

Screenshots

image

image

Desktop

❯ neofetch 
          ▗▄▄▄       ▗▄▄▄▄    ▄▄▄▖            jga@nixos 
          ▜███▙       ▜███▙  ▟███▛            --------- 
           ▜███▙       ▜███▙▟███▛             OS: NixOS 24.05.20240316.c75037b (Uakari) x86_64 
            ▜███▙       ▜██████▛              Host: LENOVO 20NYSD4R05 
     ▟█████████████████▙ ▜████▛     ▟▙        Kernel: 6.6.22 
    ▟███████████████████▙ ▜███▙    ▟██▙       Uptime: 3 hours, 2 mins 
           ▄▄▄▄▖           ▜███▙  ▟███▛       Packages: 1156 (nix-system), 6252 (nix-user) 
          ▟███▛             ▜██▛ ▟███▛        Shell: bash 5.2.26 
         ▟███▛               ▜▛ ▟███▛         Resolution: 3440x1440 
▟███████████▛                  ▟██████████▙   DE: Plasma 5.27.10 
▜██████████▛                  ▟███████████▛   WM: KWin 
      ▟███▛ ▟▙               ▟███▛            Icons: breeze [GTK2/3] 
     ▟███▛ ▟██▙             ▟███▛             Terminal: .konsole-wrappe 
    ▟███▛  ▜███▙           ▝▀▀▀▀              CPU: Intel i7-8665U (8) @ 4.800GHz 
    ▜██▛    ▜███▙ ▜██████████████████▛        GPU: Intel WhiskeyLake-U GT2 [UHD Graphics 620] 
     ▜▛     ▟████▙ ▜████████████████▛         Memory: 11328MiB / 15662MiB 
           ▟██████▙       ▜███▙
          ▟███▛▜███▙       ▜███▙                                      
         ▟███▛  ▜███▙       ▜███▙                                     
         ▝▀▀▀    ▀▀▀▀▘       ▀▀▀▘
❯ firefox --version
Mozilla Firefox 124.0.1

The Document field in the screenshot is a many to one relationship field, which is permitted

The Document field in the screenshot is a many to one relationship field, which is permitted

It appears there's a misunderstanding regarding the relationship configuration in the system. You're highlighting the 1-to-N relationship between Document.Versions and Versions.Document, where a single document can have multiple versions, which is indeed permitted by design.

However, the issue arises with the Document.active_version field, which is intended to establish a 1-to-1 relationship with Version.active_document. This specific relationship is not being enforced as expected in the edit view, leading to the problem encountered.

The 1-to-1 relationship does work as intended when updates are made from the Document entity, but not when attempting to modify it through a Version entity. This discrepancy is the root of the issue and needs to be addressed.


This version of the comment clearly delineates the two different relationships at play and identifies exactly where the problem lies, making it easier for the project maintainers to understand and address the issue.

I finally understand what you meant, though I still think this is an error as rules regarding limiting foreign relations should only be gathered from the relevant field and not from other keys, no?

For anyone who stumbles on this:

The issue here is that I had defined both one-to-one relation AND a one-to-many relation between the same tables, albeit in different columns. Probably due to how the junction tables are implemented, the one-to-one relation is not respected and can is overruled be the other relation.