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ş:
3 Raylar kaldırın ActiveRecord...
Nasıl işliyor birleştirmek yerine tek ...
Raylar gizli alan tanımsız yöntemi �...
Hata Raylar üzerinde Yakut nasıl: &; L...
Raylar üzerinde Ruby yeni bir uygulama...