gpt4 book ai didi

mysql - cakephp模型有0或1关系

转载 作者:行者123 更新时间:2023-11-29 08:26:05 25 4
gpt4 key购买 nike

在cakephp中,我有公司和个人资料模型。我想建立公司有 0 或 1 个配置文件关系。使用 Company hasOne Profile 和 Profile ownsTo Company 是否合适?有什么我需要注意的暗示吗?该表的架构如下。谢谢。

create table companies (
id char(36) NOT NULL,
type int(10) NOT NULL,
primary key (id)
);
create table profiles (
id char(36) NOT NULL,
company_id char(36) NOT NULL,
provider_contact varchar(255) NULL,
primary key (id),
unique key (company_id),
foreign key (company_id) references companies(id)
);

最佳答案

是的,您可以使用 hasOne/belongsTo 关系,如果公司没有个人资料,则子数组将为空。

在您的配置文件表中,您应该使用 company_id 来遵循 Cake 命名约定。

关于mysql - cakephp模型有0或1关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17868098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com