当外键在json列中时如何建立关系

时间:2017-07-26 14:19:17

标签: php mysql laravel laravel-query-builder

有关如何在JSON内部使用外键的方法吗?

尝试使用查询构建器,但它只返回一个任务并在位置模型中。

 $positions = DB::table('positions')
     ->join('tasks', function ($join) {
         $join->on('positions.id', '=', 'tasks.data->to_position->id');
     })
     ->get();
{ 
    "id": 14, 
    "code": "002", 
    "level": 1, 
    "side": "right", 
    "street_id": 1, 
    "position_type_id": 1, 
    "position_state_id": 2, 
    "granel": 0, 
    "kind": "picking", 
    "created_at": "2017-07-11 15:37:11", 
    "updated_at": "2017-07-14 16:36:38", 
    "task_state_id": 3, 
    "task_type_id": 2, 
    "data": "{\"orders\": [48], \"user_id\": 1, \"from_dock\": \"Muelle de ingreso pañol\", \"date_stored\": {\"date\": \"2017-07-14 16:36:38.000000\", \"timezone\": \"America/Argentina/Buenos_Aires\", \"timezone_type\": 3}, \"to_position\": {\"id\": 9, \"code\": \"002\", \"kind\": \"picking\", \"side\": \"right\", \"level\": 1, \"pivot\": {\"position_id\": 9, \"packaging_id\": 92, \"packaging_max\": 150, \"packaging_units\": 0, \"single_product_units\": 0}, \"state\": {\"id\": 3, \"state\": \"RESERVED\", \"description\": \"Tiene tareas en proceso asignandole stock\"}, \"granel\": 0, \"street\": {\"id\": 1, \"code\": \"100\", \"pallets\": 0, \"sector_id\": 1, \"description\": \"Pañol 100\", \"accept_picking\": 1}, \"street_id\": 1, \"position_type_id\": 1, \"position_state_id\": 3}, \"packaging_id\": 92, \"packaging_quantity\": 1}", 
    "finished": null 
},

0 个答案:

没有答案