我有一个关系,当我使用with("relationship")
时,它实际上正确地返回了连接值.问题是我怀疑它是使用一个循环来获取值,所以我想判断生成的SQL.问题是生成的SQL根本不包括连接的表.
json_encode(User::find(1)->materials()->where("id", 1)->with("exerciseRecords")->get()->toArray());
正确给出:
"[{"id":8091,...,"exercise_records":[{"id":28,...,"updated_at":"2023-12-09T01:22:51.000000Z"}]}]"
但
> User::find(1)->materials()->where("id", 1)->with("exerciseRecords")->toSql();
只是给
"select * from `materials` where `materials`.`user_id` = ? and `materials`.`user_id` is not null and `id` = ?"
这是否意味着我应该使用循环来解释这绝对是does?还是那toSql
个不可信?