我有以下表格:
user: id, name, credit_card_id
credit_card: id, value
balance: id, value, credit_card_id
应该如何从实体中获取与用户相关的User
所有实体的Doctrine 映射?Balance
CreditCard
我尝试过OneToMany
关系但没有运气:
class User {
/**
* @var integer
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
protected $name;
/**
* @var CreditCard
* @ORM\OneToOne(targetEntity="CreditCard", inversedBy="user")
* @ORM\JoinColumn(name="credit_card_id", referencedColumnName="id")
*/
protected $creditCard;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Balance", mappedBy="user")
*/
protected $balances;
}
class Balance {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var float
*
* @ORM\Column(name="value", type="float")
*/
protected $value;
/**
* @var CreditCard
*
* @ORM\ManyToOne(targetEntity="CreditCard")
* @ORM\JoinColumn(name="credit_card_id", referencedColumnName="id")
*/
protected $creditCard;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="User", inversedBy="balances")
*/
protected $user;
}
class CreditCard
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="value", type="string")
*/
protected $value;
/**
* @var User
*
* @ORM\OneToOne(targetEntity="User", mappedBy="creditCard")
*/
protected $user;
}