Hello,
I have the following situation in a rails application, where A, B and
C are models (objects) and are linked in the following way:
A :has_many B
A :has_many C, :as => :sumtinable
B :belongs_to A
B :has_many C, :as => :sumtinable
C :belongs_to :sumtinable,

olymorphic => true
I want to count all the Cs that belongs to A (directly and through B).
I came up with a query:
select count(*) from C where sumtinable_type='B' AND sumtinable_id IN
(select id from B where A_id=1) OR sumtinable_type='A' AND
sumtinable_id=1
The query works and fill my needs but I would like to know if there's
a Rails (efficient) way of doing the same thing?
I would like the database to do the work and avoid iteration in Ruby.
Regards
Geoffroy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---