mysql - How to use left join in rails? -


i using rake file , code

task :terminate_conference_channel, [ :circle ] => :environment |t, args|     abort "no circle" unless args[:circle]     activerecord::base.transaction       begin         circlenum = args[:circle]         circle = circle.find_by circle_number: circlenum         if circle.present?             if circle[:conference2_total_channels].present?                 conf = confbridge.find(:first, :conditions => ["confbridges.cid = ?",circle.circle_number],              end          end       rescue exception => e         activerecord::rollback         logger.info "error terminating"       end     end end 

how can select statement using join

how can convert stament rails?

select     c.id,     c.confno,     c.max_member,     (c.max_member - 5) additional,     (c.max_member - ifnull(p.active,0)) vacant     confbridges c left join     (select         confbridge_id,         count(uid) active             confbridge_participants             active = 1     group         confbridge_id) p     on c.id = p.confbridge_id     cid = '0090000092' order     vacant desc 
conf = confbridge.find(:first, :conditions => ["confbridges.cid = ?",circle.circle_number], 

this model

class confbridge < activerecord::base   has_many :confbridge_schedules, :dependent => :destroy    validates :confno, uniqueness: true, :allow_nil => true, :allow_blank => true  end 

thanks :)


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -