Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 fluent query is returning duplicated records when in MySQL there is none

I have a small problem with my query.

I have a view that displays the latest movies limit 10.

The problem I'm having is that it is showing records twice.

When I check the database there is only one record so there is not duplicated records. My view generates:

Clerks II
Clerks II
50/50
50/50

When it suppose to be only 1 of each not 2 of each.

This is my view:

@foreach ($latest as $last)
<li>{{HTML::link('movies/' .$last->idMovie, $last->c00) }}</li>
@endforeach

This is the query

on Model:

public static function latest()
{
 $latest = DB::table('movieview')
  ->select('movieview.*','art.*')
  ->join('art', 'art.media_id', '=', 'movieview.idMovie')
  ->where('art.type', '=', 'fanart')
  ->orderBy('dateAdded', 'DESC')
  ->take(10)
  ->get();

  return $latest;
}

And lastly my controller.

I'm using a view::Composer because is a sidebar sort of like a widget:

View::composer('site/latest', function($view){
         $latest = Movies::latest();  
         $newmovie = Movies::newMovie();

            $view->with(array(
            'latest'=> $latest,
            'newmovie'=> $newmovie
            ));
        });

On a side note I moved my laravel installation into a new server. On the old server it works just fine. Am I missing something? I did all the things like composer update composer dump-autoload. I can't think of anything else.

like image 520
Christian Arroyo Avatar asked Nov 22 '25 16:11

Christian Arroyo


1 Answers

One Way to debug this kind of problems is to enable the General Query Log on your development computer, that way you can actually see the query that is being generated and discard a logic issue.

You can activate the general query log in the following way

Run this two queries in your mysql server

SET global general_log = 1;

SET global log_output = 'table';

Then you can read the log by using this query:

select * from mysql.general_log

like image 90
Gabriel Acosta Avatar answered Nov 25 '25 11:11

Gabriel Acosta