views:

105

answers:

1

I'm writing a program to manage orders and then print them.

An order is an object containing the ordering person, the date and the products this person orders. I'd like to add the amount of a certain product one orderer. E.g. 3 eggs, 2 breads.

Is there a simpler way doing this with storm (the ORM I'm using) than splitting the order into smaller pieces so that every order contains only 1 product?

+3  A: 

What's wrong with adding extra columns to the intersection table of the many-to-many relationship?

CREATE TABLE orders (
  person_id INT NOT NULL,
  product_id INT NOT NULL,
  quantity INT NOT NULL DEFAULT 1,
  PRIMARY KEY (person_id, product_id),
  FOREIGN KEY (person_id) REFERENCES persons(person_id),
  FOREIGN KEY (product_id) REFERENCES products(product_id)
);

If you use an ORM that can't access additional columns in this table while doing many-to-many queries, you should still be able to access it simply as a dependent table of either products or persons.

Bill Karwin
It's the "you should still be able to access it simply as a dependent table of either products or persons" I didn't think of that." Thanks!
Georg