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

  • Erica Griffin

    Erica Griffi

    8 HAZİRAN 2009
  • MrExcite96

    MrExcite96

    17 ŞUBAT 2011
  • Wronchi Animation

    Wronchi Anim

    9 Mayıs 2011