views:

42

answers:

3

Hi,

what kind of relation (1:1, 1:m, m:m, whatever) there is between this two tables?

CREATE TABLE IF NOT EXISTS `my_product` (
  `id` int(11) NOT NULL auto_increment,
  `price` float default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `my_product_i18n` (
  `id` int(11) NOT NULL,
  `culture` varchar(7) NOT NULL,
  `name` varchar(50) default NULL,
  PRIMARY KEY  (`id`,`culture`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


ALTER TABLE `my_product_i18n`
  ADD CONSTRAINT `my_product_i18n_FK_1` FOREIGN KEY (`id`) REFERENCES `my_product` (`id`);

Regards

Javi

+2  A: 

It is 1:m you can have several different culture in my_product_i18n connected for each id.

Edit:
It is PRIMARY KEY ('id','culture') in conjunction with the constraint that tells that you can have many my_product_i18n.

Albin Sunnanbo
+2  A: 

1 to "maybe" - there's no guarantee that there will be a row in my_product_i18n, and the composite primary key of id and culture mean that you could have multiple rows for a given id, provided that those rows are of different cultures.

David T. Macknet
+2  A: 

This is a 1:M relationship. One row in my_product can have 0, 1, or more rows in my_product_i18n based off of the culture column.

Joe Stefanelli