我已将贷款表与出价表相关联,其中单笔贷款可以有多个出价。当我尝试获取贷款时,我应该获得投标详情,但我无法得到它。
我的实体是:
class Loan extends Base {
//....
/**
* @ORM\OneToMany(targetEntity="Bid", mappedBy="loan")
*/
protected $bids;
//....
}
class Bid extends Base {
//....
/**
* @ORM\ManyToOne(targetEntity="Loan", inversedBy="bids")
* @ORM\JoinColumn(name="loan_id", referencedColumnName="id",
onDelete="CASCADE")
*
*/
protected $loan;
//....
}
我的输出是(参见贷款明细中的出价):
{
"loan_amount_required": 30000,
"interest_rate": 3,
"loan_duration": 1,
"loan_validity": 5,
"status": "active",
"loan_created": "2015-11-27 12:35:56",
"user": {
"fname": "",
"lname": "",
"email": "",
"password": "",
"is_active": true,
"random_number": ,
"role": "user",
"balance": 0,
"last_seen": "........",
"notify_me": true,
"id": 34
},
"bids": [
{}
],
"id": 71
}
答案 0 :(得分:0)
在Loan构造函数中尝试:
// ...
use Doctrine\Common\Collections\ArrayCollection;
class Loan extends Base
{
// ...
public function __construct()
{
$this->bids = new ArrayCollection();
}
}