[Doctrine] #1626: Option to prevent autoinstantiation of foreign records during get() operations

6 views
Skip to first unread message

Doctrine

unread,
Oct 30, 2008, 6:16:38 AM10/30/08
to doctri...@googlegroups.com
#1626: Option to prevent autoinstantiation of foreign records during get()
operations
-----------------------------------+----------------------------------------
Reporter: adamthehutt | Owner: romanb
Type: defect | Status: new
Priority: major | Milestone: 1.1.0
Component: Relations | Version: 1.0.3
Keywords: | Has_test: 0
Mystatus: Pending Core Response | Has_patch: 0
-----------------------------------+----------------------------------------
By default, accessing $record->Related automatically instantiates a new
related Record object if one doesn't already exist. This is not always the
desired behavior, especially in cases where the related record is
"optional" (i.e. 1 to 0/1).

There should be an 'autoInstantiate' option when defining a hasOne()
relationship. For backwards compatability, the default behavior should not
change. But if one sets 'autoInstantiate' => false, then a non-existing
related object must be explicitly created.

I'm working on a test and patch for this, which I'll attach when I have
them.

--
Ticket URL: <http://trac.doctrine-project.org/ticket/1626>
Doctrine <http://www.phpdoctrine.org>
PHP Doctrine Object Relational Mapper

Doctrine

unread,
Oct 30, 2008, 9:52:36 AM10/30/08
to doctri...@googlegroups.com
#1626: Option to prevent autoinstantiation of foreign records during get()
operations
--------------------------+-------------------------------------------------
Reporter: adamthehutt | Owner: romanb
Type: defect | Status: new
Priority: major | Milestone: 1.1.0
Component: Relations | Version: 1.0.3
Resolution: | Keywords:
Has_test: 0 | Mystatus: Pending Core Response
Has_patch: 1 |
--------------------------+-------------------------------------------------
Changes (by adamthehutt):

* has_patch: 0 => 1

Comment:

I've attached a patch which seems to add this feature without breaking
anything (existing tests pass).

--
Ticket URL: <http://trac.doctrine-project.org/ticket/1626#comment:1>

Doctrine

unread,
Oct 30, 2008, 11:51:42 AM10/30/08
to doctri...@googlegroups.com
#1626: Option to prevent autoinstantiation of foreign records during get()
operations
--------------------------+-------------------------------------------------
Reporter: adamthehutt | Owner: romanb
Type: defect | Status: new
Priority: major | Milestone: 1.1.0
Component: Relations | Version: 1.0.3
Resolution: | Keywords:
Has_test: 0 | Mystatus: Pending Core Response
Has_patch: 1 |
--------------------------+-------------------------------------------------
Comment (by romanb):

Just as a side note, this behavior will be gone completely in 2.0. No
auto"magic" object creations behind the scene. We've had enough "WTF?"
experiences and bugs or bogus bugs with the current behavior. The minor
convenience this feature offers is not worth it.

--
Ticket URL: <http://trac.doctrine-project.org/ticket/1626#comment:2>

Doctrine

unread,
Oct 31, 2008, 6:44:43 AM10/31/08
to doctri...@googlegroups.com
#1626: Option to prevent autoinstantiation of foreign records during get()
operations
--------------------------+-------------------------------------------------
Reporter: adamthehutt | Owner: romanb
Type: defect | Status: new
Priority: major | Milestone: 1.1.0
Component: Relations | Version: 1.0.3
Resolution: | Keywords:
Has_test: 0 | Mystatus: Pending Core Response
Has_patch: 1 |
--------------------------+-------------------------------------------------
Comment (by adamthehutt):

romanb - Do you think this can make it into 1.0.5 or 1.1? Have you had a
chance to look at the patch? I'm not positive it does everything it needs
to do, but it addresses the primary use case ("hasZeroOrOne" foreign key
relations).

--
Ticket URL: <http://trac.doctrine-project.org/ticket/1626#comment:3>

Doctrine

unread,
Oct 31, 2008, 9:09:15 AM10/31/08
to doctri...@googlegroups.com
#1626: Option to prevent autoinstantiation of foreign records during get()
operations
--------------------------+-------------------------------------------------
Reporter: adamthehutt | Owner: romanb
Type: defect | Status: new
Priority: major | Milestone: 1.1.0
Component: Relations | Version: 1.0.3
Resolution: | Keywords:
Has_test: 0 | Mystatus: Pending Core Response
Has_patch: 1 |
--------------------------+-------------------------------------------------
Comment (by jwage):

It would only be possible in 1.1 because it is a new feature.

--
Ticket URL: <http://trac.doctrine-project.org/ticket/1626#comment:4>

Doctrine

unread,
Dec 1, 2008, 6:36:30 PM12/1/08
to doctri...@googlegroups.com
#1626: Option to prevent autoinstantiation of foreign records during get()
operations
-----------------------------------+----------------------------------------
Reporter: adamthehutt | Owner: romanb
Type: defect | Status: new
Priority: major | Milestone: 1.2.0
Component: Relations | Version: 1.0.3
Keywords: | Has_test: 0
Mystatus: Pending Core Response | Has_patch: 1
-----------------------------------+----------------------------------------
Changes (by jwage):

* milestone: 1.1.0 => 1.2.0


Old description:


> By default, accessing $record->Related automatically instantiates a new
> related Record object if one doesn't already exist. This is not always
> the desired behavior, especially in cases where the related record is
> "optional" (i.e. 1 to 0/1).
>
> There should be an 'autoInstantiate' option when defining a hasOne()
> relationship. For backwards compatability, the default behavior should
> not change. But if one sets 'autoInstantiate' => false, then a non-
> existing related object must be explicitly created.
>
> I'm working on a test and patch for this, which I'll attach when I have
> them.

New description:


By default, accessing $record->Related automatically instantiates a new
related Record object if one doesn't already exist. This is not always the
desired behavior, especially in cases where the related record is
"optional" (i.e. 1 to 0/1).

There should be an 'autoInstantiate' option when defining a hasOne()
relationship. For backwards compatability, the default behavior should not
change. But if one sets 'autoInstantiate' => false, then a non-existing
related object must be explicitly created.

I'm working on a test and patch for this, which I'll attach when I have
them.

--

Comment:

Can you provide a patch that shows the individual changes?

--
Ticket URL: <http://trac.phpdoctrine.org/ticket/1626#comment:5>

Reply all
Reply to author
Forward
0 new messages