Hi All,
How do I specify a composite primary key for a table in ActiveRecord?
For example the table Recipe which has the primary key [cookie id,
version
number] where cookie id is also a foreign key referencing Cookie.
Also: Thanks to Nic and Adam for helping with the Cookie -> Cooky
problem.
/Hugo
–SQL
*
CREATE* TABLE Raw_Materials
*
(*
id INT AUTO_INCREMENT*,*
name
VARCHAR*(30),*
quantity INT*,*
lastDelivery DATETIME*,*
PRIMARY KEY (id)*
);*
CREATE TABLE Cookies
(
id INT AUTO_INCREMENT*,*
name
VARCHAR*(30),*
primary key (id)
);
CREATE TABLE Recipes
(
version
INT*,*
cookie_id INT*,*
PRIMARY KEY (version, cookie_id*),*
FOREIGN KEY (cookie_id) REFERENCES Cookies*(id)*
);
CREATE TABLE Ingredients
(
version
INT*,*
cookie_id INT*,*
raw_material_id INT*,*
quantity INT*,*
PRIMARY KEY (version, cookie_id*,* raw_material_id*),*
FOREIGN KEY (version, cookie_id*)* REFERENCES
Recipes*(*
version*,* cookie_id*),*
FOREIGN KEY (raw_material_id) REFERENCES
Raw_Materials*(*id
)
);