Skip to content

Instantly share code, notes, and snippets.

@jbourassa
Created April 26, 2012 01:52
Show Gist options
  • Save jbourassa/2495147 to your computer and use it in GitHub Desktop.
Save jbourassa/2495147 to your computer and use it in GitHub Desktop.
Attempt to share entities in Doctrine2
<?php
// This is the namespace `app:` would resolve to.
namespace AppOne;
/**
* @Entity(repositoryClass="SomeClass...")
* @Table(name="user")
*/
class User extends Shared\User {
// Extend the class here if need be
}
/**
* @Entity(repositoryClass="SomeOtherClass...")
* @Table(name="address")
*/
class Address extends Shared\Address {
// Extend the class here if need be
}
<?php
namespace Shared;
/**
* @MappedSuperclass
*/
class User
{
/**
* @OneToMany(targetEntity="app:Address",
* mappedBy="party", cascade={"all"}, orphanRemoval=true)
*/
protected $addresses;
// More fields
}
/**
* @MappedSuperclass
*/
class Address
{
/**
* @ManyToOne(targetEntity="app:User",inversedBy="addresses")
* @JoinColumns({ @JoinColumn(name="User_id", referencedColumnName="id") })
*/
protected $user;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment