dirigible icon indicating copy to clipboard operation
dirigible copied to clipboard

[EDM] Add support for entities with composite primary key

Open iliyan-velichkov opened this issue 1 year ago • 1 comments

DAO API should support entities with composite primary key. For example the following table:

CREATE TABLE `oc_product_description` (
  `product_id` int(11) NOT NULL,
  `language_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `description` text NOT NULL,
  `tag` text NOT NULL,
  `meta_title` varchar(255) NOT NULL,
  `meta_description` varchar(255) NOT NULL,
  `meta_keyword` varchar(255) NOT NULL,
  PRIMARY KEY (`product_id`,`language_id`),
  KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

The config should look something like the following:

{
	"table": "oc_product_description",
	"properties": [
		{
			"name": "productId",
			"column": "product_id",
			"type": "INTEGER",
			"id": true,
			"autoIncrement": false
		},
		{
			"name": "languageId",
			"column": "language_id",
			"type": "INTEGER",
			"id": true,
			"autoIncrement": false
		},
		{
			"name": "name",
			"column": "name",
			"type": "VARCHAR"
		},
		{
			"name": "description",
			"column": "description",
			"type": "VARCHAR"
		},
		{
			"name": "tag",
			"column": "tag",
			"type": "VARCHAR"
		},
		{
			"name": "metaTitle",
			"column": "meta_title",
			"type": "VARCHAR"
		},
		{
			"name": "metaDescription",
			"column": "meta_description",
			"type": "VARCHAR"
		},
		{
			"name": "metaKeyword",
			"column": "meta_keyword",
			"type": "VARCHAR"
		}
	]
}

Note, there are two entries with "id": true. Update statements must have the two primary key columns in the where clause. When you execute find or remove you should provide an object for the keys instead of single value.

{
	"productId": 1,
	"languageId": 7
}

iliyan-velichkov avatar Feb 08 '24 07:02 iliyan-velichkov

Currently, the generated DAOs have duplicated methods because the tables have composite primary key image image image

iliyan-velichkov avatar Feb 12 '24 07:02 iliyan-velichkov