Message from discussion
OneToOne identifying relationship + persist [doctrine 2.1]
Received: by 10.14.2.15 with SMTP id 15mr672553eee.2.1320995645452;
Thu, 10 Nov 2011 23:14:05 -0800 (PST)
X-BeenThere: doctrine-user@googlegroups.com
Received: by 10.14.26.217 with SMTP id c65ls14075eea.2.canary; Thu, 10 Nov
2011 23:14:00 -0800 (PST)
Received: by 10.14.35.72 with SMTP id t48mr672849eea.11.1320995640716;
Thu, 10 Nov 2011 23:14:00 -0800 (PST)
Received: by 10.14.35.72 with SMTP id t48mr672848eea.11.1320995640701;
Thu, 10 Nov 2011 23:14:00 -0800 (PST)
Return-Path: <jas...@nerdsweide.nl>
Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180])
by gmr-mx.google.com with ESMTPS id i11si6188665eea.0.2011.11.10.23.13.59
(version=TLSv1/SSLv3 cipher=OTHER);
Thu, 10 Nov 2011 23:13:59 -0800 (PST)
Received-SPF: softfail (google.com: domain of transitioning jas...@nerdsweide.nl does not designate 209.85.215.180 as permitted sender) client-ip=209.85.215.180;
Authentication-Results: gmr-mx.google.com; spf=softfail (google.com: domain of transitioning jas...@nerdsweide.nl does not designate 209.85.215.180 as permitted sender) smtp.mail=jas...@nerdsweide.nl
Received: by eyg5 with SMTP id 5so4083823eyg.25
for <doctrine-user@googlegroups.com>; Thu, 10 Nov 2011 23:13:59 -0800 (PST)
Received: by 10.14.17.207 with SMTP id j55mr869670eej.211.1320995637580;
Thu, 10 Nov 2011 23:13:57 -0800 (PST)
Return-Path: <jas...@nerdsweide.nl>
Received: from [192.168.1.80] (77-73-227-253.xdsl.nextpertise.nl. [77.73.227.253])
by mx.google.com with ESMTPS id 49sm29421342eec.1.2011.11.10.23.13.56
(version=TLSv1/SSLv3 cipher=OTHER);
Thu, 10 Nov 2011 23:13:57 -0800 (PST)
Content-Type: text/plain; charset=iso-8859-1
Mime-Version: 1.0 (Apple Message framework v1251.1)
Subject: Re: [doctrine-user] OneToOne identifying relationship + persist [doctrine 2.1]
From: "Jasper N. Brouwer" <jas...@nerdsweide.nl>
In-Reply-To: <CADyq6s+j5xMGFMPDFw2z7rGuvPEjOdKCwX1hi5TqCQ5FNj68jw@mail.gmail.com>
Date: Fri, 11 Nov 2011 08:13:57 +0100
Content-Transfer-Encoding: quoted-printable
Message-Id: <0F948ACA-C77B-4F5C-A52F-30E95BB34...@nerdsweide.nl>
References: <CANsufjjuU+V24QBZEx2isMWnfoTVnqb-4Ee6SACdZutqTUb...@mail.gmail.com> <CANsufjjMm5NJncNDxSFYLirORKnwSX99ODvLpKu7kEQovi8...@mail.gmail.com> <BAB4074B-ABA4-4E40-99ED-95E369B32...@nerdsweide.nl> <CADyq6s+j5xMGFMPDFw2z7rGuvPEjOdKCwX1hi5TqCQ5FNj6...@mail.gmail.com>
To: doctrine-user@googlegroups.com
X-Mailer: Apple Mail (2.1251.1)
I agree with Marco here.
If you really have to serialize Entities, don't forget to merge them =
back into the EntityManager (when you need it managed). But it will save =
you from a lot of headaches if you can avoid this.
Tip: Create an authentication class that will lazy-load the user for =
you:
class Auth
{
protected $user =3D false;
public function getUser()
{
if( false =3D=3D=3D $this->user ) {
if( isset( $_SESSION['user_id'] )) {
$this->user =3D $em->getReference( =
$_SESSION['user_id'] ); // make sure $em is something real
} else {
$this->user =3D null;
}
}
return $this->user;
}
}
For your convenience you can make this class static of a singleton (like =
Zend_Auth), and also build in other methods in order to handle =
authentication on you application.
--=20
Jasper N. Brouwer
On 11-11-2011, at 02:51, Marco Pivetta wrote:
> As I stated before on IRC:
> - Serializing entities is not forbidden, but if you can avoid it... =
Just don't serialize them!
> - Instead of serializing entities, I'd serielize just their =
identifiers to be able to retrieve them easily. It adds some overhead, =
but reduces code complexity and the possibility of encountering bugs by =
a huge lot!
> Marco Pivetta
> http://twitter.com/Ocramius
> http://marco-pivetta.com