【发布时间】:2015-06-30 00:20:41
【问题描述】:
我有以下 ORM 返回的 JSON
[
{
"id": 3,
"name": "Card Department",
"name_burmese": "Card Department",
"is_active": "1",
"created_at": "2014-11-23 07:02:07",
"updated_at": "2014-11-23 07:02:07",
"orm_bank_contact": []
},
{
"id": 1,
"name": "Loan Department",
"name_burmese": "Loan Department",
"is_active": "1",
"created_at": "2014-11-23 07:01:16",
"updated_at": "2015-02-24 09:05:35",
"orm_bank_contact": []
},
{
"id": 4,
"name": "Remittance Department",
"name_burmese": "Remittance Department",
"is_active": "0",
"created_at": "2015-02-24 09:43:25",
"updated_at": "2015-04-17 12:26:07",
"orm_bank_contact": []
},
{
"id": 2,
"name": "Deposit Department",
"name_burmese": "Deposit Department",
"is_active": "1",
"created_at": "2014-11-23 07:01:34",
"updated_at": "2015-04-20 14:04:27",
"orm_bank_contact": [
{
"id": 27,
"bank_department": 2,
"mobile": "9843139168",
"phone": "9843139168",
"email": "shresthabeenu@gmail.com",
"contact_person": "Binu Shrestha",
"address": "No. 416, Mahabandoola Road, Kyauktada Township, Yangon, Myanmar",
"is_active": "1",
"created_at": "2015-04-15 08:50:16",
"updated_at": "2015-04-15 08:50:16",
"bank_id": 13
}
]
}
]
但我只需要
[
{
"id": 2,
"name": "Deposit Department",
"name_burmese": "Deposit Department",
"is_active": "1",
"created_at": "2014-11-23 07:01:34",
"updated_at": "2015-04-20 14:04:27",
"orm_bank_contact": [
{
"id": 27,
"bank_department": 2,
"mobile": "9843139168",
"phone": "9843139168",
"email": "shresthabeenu@gmail.com",
"contact_person": "Binu Shrestha",
"address": "No. 416, Mahabandoola Road, Kyauktada Township, Yangon, Myanmar",
"is_active": "1",
"created_at": "2015-04-15 08:50:16",
"updated_at": "2015-04-15 08:50:16",
"bank_id": 13
}
]
}
]
我需要在急切加载的对象上获取带有子项的记录
我在下面尝试过
$bank_contact = BankDepartment::with(array('OrmBankContact' => function($query) use($bank_id){
$query->where('bank_id', "=", $bank_id)->where('bank_department','>',0);}))
->get();
但没有运气..什么是正确的方法?
【问题讨论】:
标签: php sql laravel orm eager-loading