SORU
2 EKİM 2009, Cuma


Raylar ActiveRecord :İÇ yerine SOL BİRLEŞTİRME ile katılıyor KATIL

Bu kod var

User.find(:all, :limit => 10, :joins => :user_points,
                :select => "users.*, count(user_points.id)", :group =>
                "user_points.user_id")

aşağıdaki sql üretir

SELECT users.*, count(user_points.id) 
FROM `users` 
INNER JOIN `user_points` 
ON user_points.user_id = users.id 
GROUP BY user_points.user_id 
LIMIT 10

SOL BİRLEŞTİRME yapmak yerine İÇ User.find_by_sql dışında yol ve elle sorgu yazarak KATILMAK mümkün mü?

CEVAP
2 EKİM 2009, Cuma


Bu deneyebilirsiniz

User.find(:all, limit: 10,
            joins:  "LEFT JOIN `user_points` ON user_points.user_id = users.id" ,
            select: "users.*, count(user_points.id)", 
            group:  "user_points.user_id")

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Bogdan Gabriel

    Bogdan Gabri

    5 Aralık 2006
  • Joshua Kywn

    Joshua Kywn

    17 Mayıs 2010
  • LIVESTRONG.COM

    LIVESTRONG.C

    5 EKİM 2005