DDC-754: Support static targetEntity for Self-referencing #930

Closed
opened 2026-01-22 12:55:58 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Aug 18, 2010).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user vrtak-cz:

My idea is create BaseTreeEntity

/****
 * @MappedSuperclass 
 */
abstract class BaseTreeEntity
{
    /****
     * @Id
     * @Column(type = "integer")
     * @GeneratedValue
     * @var int
     */
    protected $id;
    /****
     * @ManyToOne(targetEntity="static")
     * @JoinColumn(name="parent_id", referencedColumnName="id")
     * @var BaseTreeEntity|NULL  
     */     
    protected $parent;
}

/****
 * @Entity
 * @property Foo|NULL $parent 
 */ 
class Foo extends BaseTreeEntity {}

/****
 * @Entity
 * @property Bar|NULL $parent 
 */ 
class Bar extends BaseTreeEntity {}
Originally created by @doctrinebot on GitHub (Aug 18, 2010). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user vrtak-cz: My idea is create _BaseTreeEntity_ ``` /**** * @MappedSuperclass */ abstract class BaseTreeEntity { /**** * @Id * @Column(type = "integer") * @GeneratedValue * @var int */ protected $id; /**** * @ManyToOne(targetEntity="static") * @JoinColumn(name="parent_id", referencedColumnName="id") * @var BaseTreeEntity|NULL */ protected $parent; } /**** * @Entity * @property Foo|NULL $parent */ class Foo extends BaseTreeEntity {} /**** * @Entity * @property Bar|NULL $parent */ class Bar extends BaseTreeEntity {} ```
admin added the New Feature label 2026-01-22 12:55:58 +01:00
admin closed this issue 2026-01-22 12:55:58 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 4, 2011):

Comment created by @guilhermeblanco:

Since you point to a different instance in each Association of child classes, the association definition cannot be declared in parent class.
If you still want to enforce this, you must define the root hierarchy class as targetEntity.

Marking the ticket as invalid.

@doctrinebot commented on GitHub (Oct 4, 2011): Comment created by @guilhermeblanco: Since you point to a different instance in each Association of child classes, the association definition cannot be declared in parent class. If you still want to enforce this, you must define the root hierarchy class as targetEntity. Marking the ticket as invalid.
Author
Owner

@doctrinebot commented on GitHub (Oct 4, 2011):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Oct 4, 2011): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#930