Martin B.
Martin B.

Reputation: 800

FOSUserBundle: Doubts about DB design

I'm developing in Symfony2 with FOSUserBundle and I am not very sure about DDBB Design. I will try to explain my situation as simple as possible. Let's we say that my project is like facebook. So you know that the Entity "User" would be the most important and relevant in the whole application, and everything is related with it.

The point is that I am not sure of how handle DB layer (tables, doctrine entities and relations) working with FOSUserBundle. By default, entity User must have all FOSUserBundle fields (username, email, token, email_canonical, so on...). So my doubt is whether I should create another entity to handle relations with other entities, something like "UserReal". It would have relation OneToOne with the first entity "User", witch will be used only for login or access purposes. Or just create one object "User" and handle everything with it.

My options:

1. - There is Entity "UserSecurity" witch extends FosUserBundle User entity, and only is limited to be used in access (login, logout, registration) cases. - There is Entity "UserReal", or just "User" witch has every fields propers from an User (name, surname, location). It has relations with other entities (like pages, groups, photos). It is the "main" entity, witch has strategy for generated values. - UserSecurity has a relation OneToOne to User through UserSecurity->id_user. - Registration must insert both entities.

  1. the other way around

    • Like point 1, but the main entity is "UserSecurity", so id will be in there and the strategy for generated values too.
    • User entity, will have field id_user with relation OneToOne to UserSecurity.
  2. Use one object

    • Extends FOSUserBundle in one entity and set all relations to it.
    • I don't like this becouse I need a clean object User who don't have security options.

I am thinking that facebook has a lot of User entity instances (one for each friend for instance), but only one instance for user logged, so will be wrong if we use this for everything.

I would like to know other opinions/suggestions.

I hope that it was not be confused (or I did not make confused).

Many thanks in advance.

Upvotes: 0

Views: 234

Answers (1)

moonwave99
moonwave99

Reputation: 22820

Just extend FOS user class, there is no need in making a OneToOne relationship with a twin entity.

Splitting in more entities induces overhead in hydration and persistance, but moreover induces a separation logic which is unneeded: you are defining your users properties [username, password, first name, last name, etc.], they all belong to the same entity.

If you need different kinds of user you should consider to compose subclasses with other entities, but that's beyond your question's scope.

Upvotes: 1

Related Questions