【发布时间】:2020-04-16 16:42:32
【问题描述】:
我的 if() 条件中的这个子查询卡住了我的代码。 任何人都有优化这个的想法?
public function handle()
{
print "???? Searching person \n";
DB::table('excercise_pessoa')->orderBy('id')->chunk(1000, function ($people) {
foreach ($people as $person) {
$excercise = Excercise::find($person->excercise_id);
$course = $excercise->grade->course;
$personReal = Pessoa::find($person->pessoa_id);
if ($course->pessoas->where('id', '=', $person->pessoa_id)->count() == 0) {
$course->pessoas()->attach($personReal);
print "???? Associating course to people ID: $person->pessoa_id \n";
}
}
});
print "???? Finished migration! \n";
}
【问题讨论】:
-
使用关系
manyToMany进行优化 -
@A.ANoman 怎么样?我需要验证课程是否没有为人们重复