C
C
Chvalov2018-01-28 03:20:57
MySQL
Chvalov, 2018-01-28 03:20:57

How to implement multilingualism with the Nested Sets model?

Have I implemented the category structure correctly using the Nested Sets model?

CREATE TABLE category (
  id INT(10) UNSIGNED AUTO_INCREMENT,
  image VARCHAR(128) NULL,
  top BOOLEAN DEFAULT FALSE COMMENT 'Популярная',
  status BOOLEAN DEFAULT TRUE COMMENT 'Отражается',
  parent_id INT(10) UNSIGNED NULL DEFAULT NULL, -- Идентификатор родительского узла
  -- NS колонки
  left_key INT(10) UNSIGNED NOT NULL DEFAULT 0, -- Точка отсчета начала ветки
  right_key INT(10) UNSIGNED NOT NULL DEFAULT 0, -- Точка остановки конца ветки
  level INT(10) UNSIGNED NOT NULL DEFAULT 0, -- Уровень узла (Количество родителей узла)

  PRIMARY KEY (`id`),
  INDEX (`parent_id`),
  CONSTRAINT FK_category_parent_id_id FOREIGN KEY (`parent_id`) REFERENCES category(`id`)
) ENGINE=InnoDB;

Multilingual:
DROP TABLE IF EXISTS category__description;
CREATE TABLE category__description (
  category_id INT(10) UNSIGNED NOT NULL,
  language_id INT(10) UNSIGNED NOT NULL,
  name VARCHAR(128) NOT NULL,
  description MEDIUMTEXT,
  meta_description VARCHAR(255),
  meta_keyword VARCHAR(255),
  PRIMARY KEY (`category_id`,`language_id`),
  INDEX (`name`),
  FOREIGN KEY (`category_id`) REFERENCES category(`id`)
) ENGINE=InnoDB;

DROP TABLE IF EXISTS language;
CREATE TABLE language (
  id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(32) NOT NULL,
  iso_code VARCHAR(5) NOT NULL,
  status BOOLEAN DEFAULT TRUE,
  PRIMARY KEY (`id`),
  INDEX (`name`)
) ENGINE=InnoDB;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2018-01-28
@BorisKorobkov

Basically correct.
But if "PostgreSQL" is specified in the tags, then "unsigned", "mediumtext", "autoincrement", "innoDB", etc. will not work there. So don't spam tags if you don't even understand their meaning.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question