【发布时间】:2020-01-19 07:07:26
【问题描述】:
假设我有一个posts 和attachments 表,我想要的是获得一个特定的帖子,并加载它的附件。
目前,我正在这样做:
$post->load([
'attachments:id,name,original_name,size,mime,category'
]);
它生成的查询是这样的:
"query" => "select `id`, `name`, `original_name`, `size`, `mime`, `category` from `attachments` where `attachments`.`attachable_id` in (4) and `attachments`.`attachable_type` = ?"
"bindings" => array:1 [
0 => "App\Post"
]
上面的查询结果是空的,因为没有转义\,如果我复制,在MySQL工作台中通过这个查询并像"App\\Post"一样转义那个斜线它正在工作。如何解决这个问题?
【问题讨论】:
标签: laravel eloquent eager-loading laravel-5.8 polymorphic-relationship