如何在一个引用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. thecustomer_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
最满意答案
也许这对你有用:
$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;
相关问答
更多-
我想我找到了答案。 Phoenix.Token非常适合我想要实现的目标。 I think I found my answer. Phoenix.Token is perfect for what I'm trying to achieve.
-
实际上, Auth::check()有以下代码 public function check() { return ! is_null($this->user()); } 如果有任何用户登录,则函数Auth::user()返回用户实例;如果没有登录,则返回null。因此,它不会检查谁登录但只检查是否有用户登录。 每当用户登录到应用程序时, Auth::login()函数首先执行此操作 $this->updateSession($id = $user->getAuthIdentifier()); 这 ...
-
Web API没有会话 - 需要检查用户是否已通过身份验证(Web API has no session - need to check if user is authenticated)[2023-06-01]
推荐的方法是使用无状态身份验证和令牌授权。 几年以来,将WebAPI配置为使用OWIN中间件集成OAuth2工作流程非常简单。 了解如何遵循本教程 。 您在OAuth2中所谓的会话项目 ,您谈的是声明 。 The recommended approach is using stateless authentication and authorization with tokens. Since some years, it's very easy to configure your WebAPI to in ... -
如果您已经定义了用户角色,则应该对其进行处理,您正在使用LoginControl,我猜您正在使用其他登录控件(如loginview)处理唱歌,并希望您将用户角色分配给它。 如果是这种情况,您可以使用LoginUser_LoggedIn事件 // suppose if you are willing to redirect a user according to his/her role protected void LoginUser_LoggedIn(object sender, EventArgs ...
-
也许这对你有用: $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', ...
-
如何在Jersey Web服务中检查经过身份验证的用户的角色(How to check the role of an authenticated user in a Jersey web service)[2023-09-15]
我还必须分别在web.xml指定安全角色:USER ADMIN