Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hasMany with reverse and key omits primary key in mysql #810

Open
maritaria opened this issue Sep 26, 2017 · 0 comments
Open

hasMany with reverse and key omits primary key in mysql #810

maritaria opened this issue Sep 26, 2017 · 0 comments

Comments

@maritaria
Copy link

	let User = db.define("user", {
		name: { type: "text", required: true, unique: true },
		task_name: String,
		task_data: Object,
		last_seen: { type: 'date', time: true },
		card_url: { type: 'text' },
	});
	
	let Group = db.define("group", {
		name: { type: "text", required: true },
		general_chat: { type: "text", required: true, unique: true },
		admin_chat: { type: "text", required: false, unique: true },
	});
	Group.hasMany("members", User, {
			rank: [ "unverified", "member", "admin" ],
		}, { reverse: "groups", key: true });

With debug enabled I get the following querries:

(orm/mysql) SHOW TABLES LIKE 'user'
(orm/mysql) CREATE TABLE `user` (`name` VARCHAR(255) NOT NULL, `task_name` VARCHAR(255), `task_data` BLOB, `last_seen` DATETIME, `card_url` VARCHAR(255), `id` INT(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`))
(orm/mysql) SELECT index_name, column_name, non_unique FROM information_schema.statistics WHERE table_schema = 'fetguard' AND table_name = 'user'
(orm/mysql) CREATE UNIQUE INDEX `name_unique` ON `user` (`name`)
(orm/mysql) SHOW TABLES LIKE 'group_members'
(orm/mysql) CREATE TABLE `group_members` (`members_id` INTEGER NOT NULL, `group_id` INTEGER NOT NULL, `rank` ENUM ('unverified','member','admin'))
(orm/mysql) SELECT index_name, column_name, non_unique FROM information_schema.statistics WHERE table_schema = 'fetguard' AND table_name = 'group_members'
(orm/mysql) CREATE INDEX `members_id_index` ON `group_members` (`members_id`)
(orm/mysql) CREATE INDEX `group_id_index` ON `group_members` (`group_id`)
(orm/mysql) SHOW TABLES LIKE 'group'
(orm/mysql) CREATE TABLE `group` (`name` VARCHAR(255) NOT NULL, `general_chat` VARCHAR(255) NOT NULL, `admin_chat` VARCHAR(255), `id` INT(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`))
(orm/mysql) SELECT index_name, column_name, non_unique FROM information_schema.statistics WHERE table_schema = 'fetguard' AND table_name = 'group'
(orm/mysql) CREATE UNIQUE INDEX `general_chat_unique` ON `group` (`general_chat`)
(orm/mysql) CREATE UNIQUE INDEX `admin_chat_unique` ON `group` (`admin_chat`)
(orm/mysql) SHOW TABLES LIKE 'group_members'
(orm/mysql) SHOW TABLES LIKE 'ticket'
(orm/mysql) CREATE TABLE `ticket` (`status` ENUM ('started','expired','submitted','completed','denied'), `task` VARCHAR(255), `pic` VARCHAR(255), `started_at` DATETIME NOT NULL, `finish_before` DATETIME NOT NULL, `signed_at` DATETIME, `id` INT(11) NOT NULL AUTO_INCREMENT, `user_id` INTEGER NOT NULL, `group_id` INTEGER NOT NULL, `admin_id` INTEGER, PRIMARY KEY (`id`))

In which you can see the querry for the group_members table has no primary key. Removing the reverse option causes a querry with primary key to be created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant