sfDoctrineGuard - how to ALWAYS join sfGuardProfile to sfGuardUser

I want to make it so that anytime the db is queried for an sfGuardUserProfile it is autmoatically joined and hydrated with its related sfGuardUser.

If i was using Propel 1.2 i would normally override the doSelectStmt method of the sfGuardUserProfilePeer class to inspect the Criteria and modify it as necessary as well as modifying the hydrate method of the sfGuardUserProfile class. Im not sure how to go about doing this in Doctrine though.

Answers


You could use Event Listeners. Read more about them in the doctrine documentation: Event Listeners

In symfony 1.4 sfGuardUser can be modified. It's by default in lib/model/doctrine/sfDoctrineGuardPLugin/sfGuardUser.class.php. You can add following preDqlSelect() method to modify the query. Note that it's not tested.

class sfGuardUser extends PluginsfGuardUser
{
  public function preDqlSelect($event)
  {
    $params = $event->getParams();
    $query  = $event->getQuery();
    $alias  = $params['alias'] . '.Profile';
    if ((!$query->isSubquery() || ($query->isSubquery() && $query->contains(' ' .     $params['alias'] . ' '))) && !$query->contains($alias)) 
    {   
      $query->innerJoin($alias);
    }   
  }
}

To make it working you need to have DQL callbacks turned on. You can do it in your ProjectConfiguration class:

  class ProjectConfiguration extends sfProjectConfiguration
  {
    public function configureDoctrine(Doctrine_Manager $manager)
    {  
      $manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);
    }  
  }

Although I agree with Coronatus, I think what you're looking to do can be achieved with:

http://www.symfony-project.org/plugins/sfGuardPlugin

See "Customize the sfGuardUser model".

Basically, the profile needs to be called "sf_guard_user_profile" and the relation set up, and then you should be able to use:

$this->getUser()->getGuardUser()->getProfile();

I think the right profile model name is needed for some config file purposes but I may be wrong.


Need Your Help

JAX-WS web services thread safety and performance concerns

java multithreading web-services thread-safety jax-ws

I understand from a few other posts and my understanding on JAX-WS web services they are not thread-safe. My web service is going to get called by 100's of clients and we need to be able to process