Skip to content

Commit

Permalink
Fix one to one relation b/w non-composite pk tables
Browse files Browse the repository at this point in the history
  • Loading branch information
achiku committed Oct 25, 2017
1 parent acf105f commit 5bb84ca
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
13 changes: 11 additions & 2 deletions example/ddl.sql
Expand Up @@ -3,6 +3,7 @@ drop table if exists order_detail;
drop table if exists customer_order;
drop table if exists sku;
drop table if exists product;
drop table if exists vendor_address;
drop table if exists vendor;
drop table if exists customer;

Expand All @@ -24,11 +25,19 @@ COMMENT ON COLUMN customer.phone_number IS 'Customer Phone Number';
create table vendor (
id bigserial primary key
, name text not null
, zip_code text not null
, address text not null
, phone_number text not null
);

create table vendor_address (
vendor_id bigint primary key
, zip_code text not null
, state text not null
, city text not null
, line1 text not null
, line2 text not null
, FOREIGN KEY(vendor_id) REFERENCES vendor (id)
);

create table product (
id bigserial primary key
, vendor_id bigint not null
Expand Down
Binary file modified example/example_gen.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 15 additions & 4 deletions example/example_gen.uml
Expand Up @@ -9,6 +9,7 @@ entity "customer" {
zip_code : Customer Zip Code
address : Customer Address
phone_number : Customer Phone Number
registered_at
}

entity "customer_order" {
Expand Down Expand Up @@ -66,22 +67,32 @@ entity "vendor" {
+ id [PK]
--
name
zip_code
address
phone_number
}

customer_order }-- customer
entity "vendor_address" {
+ vendor_id [PK]
--
zip_code
state
city
line1
line2
}

order_detail }-- sku
customer_order }-- customer

order_detail }-- customer_order

order_detail }-- sku

order_detail_approval ||-|| order_detail

order_detail_approval ||-|| order_detail

product }-- vendor

sku }-- product

vendor_address ||-|| vendor
@enduml
2 changes: 2 additions & 0 deletions planter.go
Expand Up @@ -75,6 +75,8 @@ func (k *ForeignKey) IsOneToOne() bool {
}
}
return true
case !k.SourceTable.IsCompositePK() && k.SourceColumn.IsPrimaryKey && k.TargetColumn.IsPrimaryKey:
return true
default:
return false
}
Expand Down

0 comments on commit 5bb84ca

Please sign in to comment.