budibase icon indicating copy to clipboard operation
budibase copied to clipboard

Multiple Many-to-one Relationships between the same two Tables breaks

Open Debugnium opened this issue 2 years ago • 2 comments

Hosting

  • Self
    • Method: docker compose
    • App Version: 1.1.21
    • Database: MS SQL Server

Describe the bug

Having multiple many-to-one relationships from Table A to Table B seems to break relationships: image

Expected behavior

"Employees" relationships to load an Employee when viewing "Customers" data.

Additional context

In my case, a legacy database has 3 relations between customers and employees representing different roles.

The SQL seen in the XEvent Profiler uses an or in the left join, and in the select statement, it includes all of the [Employees] columns three times... left join [Employees] on [Customers].[Employee ID] = [Employees].[Employee ID] or [Customers].[OrgEmpID] = [Employees].[Employee ID] or [Customers].[Service ID] = [Employees].[Employee ID]

This results in 3 rows with the same "Employees" data repeated 3 times in each row, rather than a single row with data for each employee.

Removing two of the three relationships fixes the issue, but then two relationships are missing.

Debugnium avatar Jul 27 '22 11:07 Debugnium

Also, having many-to-many relationship on tables A-B-C prevents us from creating one-to-many relationship on tables A-B (even though it's the same thing, it is sometimes useful in forms building)

martkaczmarek avatar Sep 16 '22 16:09 martkaczmarek

Possibly related issue in MySQL.

Message from Discord:

if I create/define an relationship with Table A to Table B, then do it Table A to Table C, the the A<->B goes away. IF I create a relationship Table B to Table A, then Table C to Table A, it works fine,

melohagan avatar Oct 28 '22 09:10 melohagan

This issue has been automatically marked as stale because it has not had recent activity.

stale[bot] avatar Dec 31 '22 19:12 stale[bot]

Closing as multiple Many->Many relationships with the same tables will no longer be supported: https://github.com/Budibase/budibase/pull/9421

This is because as well as the break, it would be substantially detrimental on performance. Better to use Custom SQL queries if you need to perform a lot of joins.

melohagan avatar Feb 02 '23 14:02 melohagan