首页 \ 问答 \ 如何在一个引用cakephp中另一个表的表中使用多个外键(How do I use multiple foreign keys in one table referencing another table in cakephp)

如何在一个引用cakephp中另一个表的表中使用多个外键(How do I use multiple foreign keys in one table referencing another table in cakephp)

使用cakephp,我有一个通用地址表,我想链接到客户,供应商,联系人。 大多数表只有1比1的关系,但我希望我的客户表有2个

也许是为了澄清:我有一个客户表

id, int
mailing_address_id, int
billing_address_id, int

和一个地址表

id,int
addr, varchar
city, varchar
etc....

现在我知道我可以将customer_id放在地址表中。 但我不想那样做,因为我有一个供应商表,联系人表和其他所有将使用地址表的表。 customer_id实际上不会与那些其他表相关。

我希望Customer模型自动链接到两个地址


Using cakephp, I have a generic address table, which I want to link to customers, vendors, contacts. most of the tables only have a 1 to 1 relationship, but I want my customers table to have 2

perhaps for clarification: I have a customers table

id, int
mailing_address_id, int
billing_address_id, int

and an addresses table

id,int
addr, varchar
city, varchar
etc....

Now I know I could put a customer_id in the addresses table. But I don't want to do that because I have a vendors table, and contacts table, and other tables that all are going to use the addresses table. the customer_id would not really be relavant to those other tables.

I'd like the Customer model to automatically link in the two addresses


原文:https://stackoverflow.com/questions/655068
更新时间:2023-08-24 18:08

最满意答案

也许这对你有用:

$email = Auth::user()->email;
$match = false;

if (Teacher::where('email','=',$email)->first() != NULL) {
    $match = true;
}

return $match;

Maybe this can work for you:

$email = Auth::user()->email;
$match = false;

if (Teacher::where('email','=',$email)->first() != NULL) {
    $match = true;
}

return $match;

相关问答

更多