Answer the question
In order to leave comments, you need to log in
Why can't I get an entity from a repository in Doctrine?
There is an essence
/**
* @Entity
* @Table(name="`address`")
*/
class Address
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="IDENTITY")
*/
protected $address_id;
/**
* @Column(type="string")
*/
protected $firstname;
/**
* @ManyToOne(targetEntity="Customer", inversedBy="address")
* @JoinColumn(name="customer_id", referencedColumnName="customer_id")
*/
protected $customer;
/**
* @Entity(repositoryClass="\Core\Repositories\CustomerRepository")
* @Table(name="`customer`")
*/
class Customer
{
public function __construct()
{
$this->addresses = new ArrayCollection();
}
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="IDENTITY")
*/
protected $customer_id;
/**
* @OneToMany(targetEntity="Address", mappedBy="customer", cascade={"persist", "remove"})
* @JoinColumn(name="customer_id", referencedColumnName="customer_id")
*/
protected $addresses;
$this->entityManager->getRepository(Address::class)->findOneBy(['address_id' => 1]);
Uncaught Doctrine\Common\Proxy\Exception\UnexpectedValueException: Your proxy directory "/tmp" must be writable
/**
* @ManyToOne(targetEntity="Customer", inversedBy="address")
* @JoinColumn(name="customer_id", referencedColumnName="customer_id")
*/
protected $customer;
Answer the question
In order to leave comments, you need to log in
https://www.doctrine-project.org/projects/doctrine...
/**
* @OneToMany(targetEntity="Address", mappedBy="customer", cascade={"persist", "remove"})
* @JoinColumn(name="customer_id", referencedColumnName="customer_id")
*/
protected $addresses;
Address::$customer_id
is it the primary key? /**
* @Entity
* @Table(name="`address`")
*/
class Address
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="IDENTITY")
*/
protected $address_id;
/**
* @Column(type="string")
*/
protected $firstname;
/**
* @ManyToOne(targetEntity="Customer", inversedBy="address")
* @JoinColumn(name="customer_id", referencedColumnName="customer_id")
*/
protected $customer;
}
/**
* @Entity(repositoryClass="\Core\Repositories\CustomerRepository")
* @Table(name="`customer`")
*/
class Customer
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="IDENTITY")
*/
protected $customer_id;
/**
* @OneToMany(targetEntity="Address", mappedBy="customer", cascade={"persist", "remove"})
*/
protected $addresses;
public function __construct()
{
$this->addresses = new ArrayCollection();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question