2016-08-24 23 views
6

Bu sorgu 5.2'de çalışır:sorgu laravel bana hata vermek 5,3

$galleries = Gallery::with(array(
      'images' => function ($query) { 
       $query->orderBy('order', 'asc'); 
      } 
     )) 
     ->with('votes') 
     ->leftJoin('votes', 'votes.votable_id', '=', 'gallery.id') 
     ->selectRaw(
      'gallery.*, count(case votes.status when "upvote" then 1 else null end) - count(case votes.status when "downvote" then 1 else null end) as points' 
     ) 
     ->where('votes.votable_type','App\Gallery') 
     ->groupBy('gallery.id') 
     ->orderBy('points', 'desc') 
     ->published()->orderBy('gallery.created_at', 'desc')->paginate(30); 

ben 5.3 bu çalıştırdığınızda ben bu

olsun, oy olan tüm galerileri seçmek çalışıyorum
1/2 PDOException in Connection.php line 333: SQLSTATE[42000]: 
Syntax error or access violation: 1055 'images.gallery.title' isn't in GROUP BY 

SQLSTATE[42000]: Syntax error or access violation: 1055 'images.gallery.title' isn't in 
GROUP BY (SQL: select gallery.*, count(case votes.status when "upvote" then 1 else null end) - count(case votes.status when "downvote" then 1 else null end) 
as points from `gallery` left join `votes` on `votes`.`votable_id` = `gallery`.`id` 
where `votes`.`votable_type` = App\Gallery and `published` = 1 group by `gallery`.`id` 
order by `points` desc, `gallery`.`created_at` desc limit 30 offset 0) 
+0

'GROUP BY' deyimine 'gallery.title' misyonunu eklemeyi denediniz mi? – mazedlx

+0

evet bunu denedim, o zaman galeri tablosundaki tüm sütunları eklemem gerektiğini söyledi, bu yüzden ben de bununla bitiyorum: -> groupBy ('gallery.id', 'gallery.title', 'gallery.hash' 'gallery.user_id', 'gallery.published', 'gallery.views', 'gallery.created_at', 'gallery.updated_at') ancak bana doğru bakmıyor. Sence haklı mı? –

+1

Dokümantasyon, yükseltme rehberinde “join” metodunun yeniden yazıldığı 5.3'e değinir. https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0 – mazedlx

cevap

1

belgelerinde başı olarak katılacak sorgu bu Referans isterim: - https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0

$galleries = Gallery::with(array(
     'images' => function ($query) { 
      $query->orderBy('order', 'asc'); 
     } 
    )) 
    ->with('votes') 
    ->leftJoin('votes',function($query){ 
       $query->on('votes','gallery')->where('votes', 'votes.votable_id', '=', 'gallery.id')->where('votes.votable_type','App\Gallery'); })->selectRaw(
     'gallery.*, count(case votes.status when "upvote" then 1 else null end) - count(case votes.status when "downvote" then 1 else null end) as points' 
    ) 
    ->groupBy('gallery.id') 
    ->orderBy('points', 'desc') 
    ->published()->orderBy('gallery.created_at', 'desc')->paginate(30); 
+0

Merhaba Hamza, şu hatayı alıyorum: SQLSTATE [42000]: Sözdizimi hatası veya erişim ihlali: 1064 SQL sözdiziminde bir hata var ; 'gallery.id 'votes' = yakınında kullanmak için doğru sözdizimi için MariaDB sunucu sürümünüze karşılık gelen kılavuzu kontrol edin. 'votes'.'votable_type' = nerede? ve 'yayınlanan '=? satır 1'deki satır (SQL: "galeri" nin toplandığı toplama sayısını (*) "oy" = "galeri" galeri.id "oy" = oy "=" oy "=" oy "anlamına gelir. = App \ Gallery ve 'broadcast' = 'gallery'.'id' tarafından 1 grup) hakkında nelerden bahsediyorsunuz? –

+0

Sorgudaki Sql() yöntemine koşuyorum ve bu, oluşturduğu sql: "galeri seçin. *, Sayın (" oylama "," sonra "1 null sonu) durumunda oy ver.status) - sayım (case down.status" downvote "olduğunda) sonra 1 tane daha null)) 'galeri' 'nin puanları' 'oy' 'oy' = 'galeri' galeri.id 'oy' = 'nerede' oy '.'votable_type' =? ve 'yayınlanan '=? grup tarafından 'gallery'.'id' tarafından sipariş,' gallery'.'created_at' desc " –

+0

Cevabını güncelledim ve bunu deneyin ve istediğiniz çıktıyı elde edip edemeyeceğinize bakın –

11

config/database.php klasörünüze gidin. Mysql yapılandırma dizisinde strict => true değerini strict => false olarak değiştirin ve her şey güzel bir şekilde çalışacaktır.

+2

paylaştığınız için teşekkürler. –