ruby on rails - Count on HABM has_many association -


i have models trader, location , service

they setup per below

class trader < activerecord::base   has_many :services   has_and_belongs_to_many :locations end  class location < activerecord::base   has_and_belongs_to_many :traders end  class service < activerecord::base   belongs_to :trader end 

i specific location able return traders contains, in order of number of services trader provides.

i have read few suggestions taking account associations between 2 models have 3. have put ridiculously complex method using arrays, array pointers , case statements spare reading.

what's best way achieve want?

i'd add :counter_cache on trader's services association. can sort services_count , don't have reach down table @ scope.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -