教义2.1 - 将实体映射到多个表 [英] Doctrine 2.1 - Map entity to multiple tables

查看:150
本文介绍了教义2.1 - 将实体映射到多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据库情况:

wp_users (user table generated by wordpress)
ID | user_login | ... 

wp_sp_user (extension to the wp_users table)
ID (FK) | surname | address | ... 

现在我已经尝试了几个小时,将这两个表融合成一个单个用户实体,例如:

Now I've already been trying for hours to "fuse" those two tables into one single User entity, e.g:

class User {
  var ID;
  var user_login;
  var surname;
  var address;
  ...
}

有没有办法完成这样的映射没有修改 wp_user 表(我不想为更新的原因)?

Is there any way to accomplish such a mapping without modifying the wp_user table (which I don't want to do for updating reasons)?

推荐答案

这是不可能的。这样做也没有意义。

This is not possible. It also doesn't make sense to do so.

您将需要在MySQL中将表合并在一起,并为该表创建一个Doctrine实体。这是唯一可以确保数据清理和完全正常化的方法。

You will need to physically merge the tables together in MySQL and create a Doctrine entity for that table. This is the only way you can ensure your data is clean and fully normalized.

另一种可能的解决方案是为每个表创建一个实体,并使用业务对象组合结果从每个。这根本不是一个非常好的解决方案,因为您必须处理应用程序层的约束,并且您将启动的查询量增加一倍。

Another possible solution is to create one entity for each table and use a business object to combine results from each. This is not a very nice solution at all, as you will have to handle constraints on the application layer, and you will double the amount of queries you launch.

这篇关于教义2.1 - 将实体映射到多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆