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

  • Distractify

    Distractify

    1 Aralık 2011
  • LearnCode.academy

    LearnCode.ac

    20 Aralık 2012
  • MatheusDosGames

    MatheusDosGa

    28 Aralık 2011