Skip to content

Duplicate relations if multiple indexes on foreign key #35

@cyrillbolliger

Description

@cyrillbolliger

Many thanks for this super handy project!

I noticed a small bug: If there are two indexes on a foreign key, the relation is duplicated even though there is only one foreign key column. Here a minimal example to reproduce the issue:

For the following table definition

create table foo
(
    id serial primary key
);

create table bar
(
    id     serial primary key,
    foo_id int references foo,
    name   int
);

create index on bar (foo_id);
create unique index on bar (name, foo_id);

planter creates the following output

@startuml
hide circle
skinparam linetype ortho

entity "**bar**" {
  + ""id"": //serial [PK]//
  --
  ""foo_id"": //integer [FK]//
  ""name"": //integer //
}

entity "**foo**" {
  + ""id"": //serial [PK]//
  --
}

"**bar**"   }--  "**foo**"

"**bar**"   }--  "**foo**"
@enduml

whereas the correct output would be

@startuml
hide circle
skinparam linetype ortho

entity "**bar**" {
  + ""id"": //serial [PK]//
  --
  ""foo_id"": //integer [FK]//
  ""name"": //integer //
}

entity "**foo**" {
  + ""id"": //serial [PK]//
  --
}

"**bar**"   }--  "**foo**"
@enduml

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions