Two tables relation with sfDoctrineGuard user table (symfony)



I have started in my web application a part who users needs to be autenticated to work with it. I have two tables related: Customer and Enterprise.... the first one are users who want to buy a product and the second one are "users" who want to sell products.

What is better way to do that? Relation 1:1 with user_table? how can i differentiate wich one user type is? Because user types only can edit some information and enterprise have acces to another modules...

Thanks a lot.


You could use the <a href="http://www.doctrine-project.org/Doctrine_Record/1_2#method_hasreference" rel="nofollow">hasReference()</a> function on the model.

E.g. your model Customer has a relation to User like this:

Customer: relations: user: local: id foreignID: id foreignAlias: customer

Then you can test whether the user is of type customer (in the controller):


To make this easier you can add this method to your myUser class:

public function isCustomer() { return $this->getGuardUser()->hasReference('customer'); }

Same of course for Enterprise.

Even using two different tables, you can make use of the hasCredential() method, and this is the easiest way if you only want to check for permission.<br /> If you want to access certain attributes of the enterprise and customer user you can also combine both approaches.


Well, assuming that Customers and Enterprise users have different permissions, I would go with the user group approach. This fits better to the group model of sfGuard. If you then know that a user is in group Customer, you know that the user has a reference to a customer object.

But this means of course that you have to assign the the right group to a new user in order to work correctly.


Do your tables really need to be separate? If not, you could use the standard sf_guard_user table provided with the sfGuard plugin for both types of user, and then use the groups functionality to assign the user to either the "Customer" group or the "Enterprise" group.

Checking the group that the user belonged to would allow you to display (or hide) the appropriate content for that user type. Something like this in your action:

if ($this->getUser()->hasCredential("enterprise")) { // code related to Enterprise customers only }

or using the $sf_user variable in your view/templates.


  • Jira, Tomcat and JBoss behind Apache
  • NoMethodError when I try to acces a field of an object taken from the DB
  • How to customize information in reporting manager
  • Can't expand nodes in TreeView (WinForms)
  • javascript created control values are not posting to server
  • A two-user tic tac toe using JSF
  • Accessing resx file from another project / assembly
  • Set up a cron every hour
  • Adding a child to Viewport3D asynchronously gives “This API was accessed with arguments from the wro
  • Android ICS x86 on VirtualBox with Internet Connection
  • React native how to get “getPackageManager()”
  • How to display related data from dataset in wpf datagrid
  • How to get not only single record but all records that belong to specific search query
  • Loopback API include filters not working as expected
  • Yii: how to show a field from a related table's related table?
  • Visual Studio 2015 XAML Resource Dictionary Error
  • Models with two hasOne relations to same table
  • EJB @Schedule issue
  • React textarea with value is readonly but need to be updated
  • Batching in py2neo
  • How do we set maximum_bad_records when loading a Bigquery table from dataflow?
  • Checking if the Faye server exists before running it for my Rails app
  • how to change api_token column in token guard
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • Can I make an Android app that runs a web view in Chrome 39?
  • Web-crawler for facebook in python
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Turn off referential integrity in Derby? is it possible?
  • Authorize attributes not working in MVC 4
  • MATLAB: Piecewise function in curve fitting toolbox using fittype
  • Busy indicator not showing up in wpf window [duplicate]
  • Running Map reduces the dimensions of the matrices
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?