Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2.1 - Map entity to multiple tables

I have the following database situation:

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;
  ...
}

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)?

like image 556
MrMuh Avatar asked Aug 25 '11 23:08

MrMuh


1 Answers

Some times database refactoring is not possible or the table has his own "raison d'être". In this cases you can use inheritance. Your User class can extens Account. Map Account to wp_users and extend it with wp_sp_user table. User class will use columns of the two tables.

Here is the doctrine documentation:

https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/inheritance-mapping.html

like image 60
TlmaK0 Avatar answered Sep 28 '22 00:09

TlmaK0