Laravel, why do I have so many queries? -
controller
    $attendees = attendee::with('user')->get();     return view::make('admin.attendees.index', compact('attendees'));   attendee model
public function user()                                                                                                                                                                                                                   |        if( !( $user->hasrole('admin') || $user->hasrole('programmer') )) {                                                                                                                                                                                                                                        |            return redirect::to('/');     return $this->belongsto('user');                                                                                                                                                                                                     | }       view
@foreach($attendees $attendee)       <td>{{link_to_route('admin.users.show', $attendee->user->username, $attendee->user->id)}}</td> @endforeach   223 queries
select * `users` `users`.`id` = '4' limit 1600μs select `roles`.*, `assigned_roles`.`user_id` `pivot_user_id`, `assigned_roles`.`role_id` `pivot_role_id` `roles` inner join `assigned_roles` on `roles`.`id` = `assigned_roles`.`role_id` `assigned_roles`.`user_id` = '4'630μs select * `attendees`1.24ms select * `users` `users`.`id` in ('5', '1', '3', '8', '9', '10')780μs select * `users` `users`.`id` = '5' limit 1680μs select * `users` `users`.`id` = '5' limit 1650μs select * `users` `users`.`id` = '5' limit 1680μs select * `users` `users`.`id` = '5' limit 1590μs select * `users` `users`.`id` = '1' limit 1  <continues each user id>   i using phpdebugbar show queries.
migration
schema::table('attendees', function(blueprint $table) {          $table->foreign('user_id')->references('id')->on('users')                                    ->ondelete('cascade')                                    ->onupdate('no action');   am doing wrong causing query run on , on again?
the eager load should name of relationship function, not relationship's model, , it's apparently case sensitive:
$attendees = attendee::with('user')->get();      
Comments
Post a Comment