Created
June 7, 2012 22:54
-
-
Save joevandyk/2892196 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| begin; | |
| -- orders have many line_items, refunds have many line_items, but a refund can't be associated with line items from different orders. | |
| create table orders(id integer primary key); | |
| create table line_items(id integer primary key, order_id integer references orders); | |
| create table refunds(id integer primary key); | |
| create table line_items_refunds(line_item_id integer references line_items, refund_id integer references refunds); | |
| insert into orders values (1); | |
| insert into orders values (2); | |
| -- each order has one associated line item. | |
| insert into line_items values (1, 1); | |
| insert into line_items values (2, 2); | |
| -- create a refund.. | |
| insert into refunds values (1); | |
| -- Problem! We have line items from two different orders associated with the refund. | |
| insert into line_items_refunds (line_item_id, refund_id) values (1, 1); | |
| insert into line_items_refunds (line_item_id, refund_id) values (2, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment