douzhou7124 2017-10-23 12:44
浏览 36
已采纳

Yii2中hasMany关系的MySQL列定义

I have an employees table defined with their alphanumeric employee_id (currently 9-characters but can increase upto 15) as the key:

CREATE TABLE employee (
    emp_id VARCHAR(15) NOT NULL PRIMARY KEY,
    emp_name VARCHAR(255) NOT NULL,
    ...
);

Now, I've to create a Group entity where each employee can be part of multiple groups:

CREATE TABLE group (
    group_id VARCHAR(15) NOT NULL PRIMARY KEY,
    group_name VARCHAR(255) NOT NULL,
    employees ????, <--- how should this be defined?
    FOREIGN KEY fk_emp(employees) REFERENCES employee(emp_id)
);

I can create the controller and view for this using gii or manually, without an issue. The group creation/update form will have a multi-select for employees.

As an alternative, does Yii2 support sets?

  • 写回答

1条回答 默认 最新

  • dongque8332 2017-10-23 12:54
    关注

    Like this:

    enter image description here

    You link the group and employee tables together via a third table. This allows you to link employees into many groups, and groups to link to many employees as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来