Class: ForemanDatacenter::Site
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ForemanDatacenter::Site
- Includes:
- Authorizable, ScopedSearchExtensions
- Defined in:
- app/models/foreman_datacenter/site.rb
Class Method Summary collapse
-
.find_by_house ⇒ Object
(key, operator, value).
Instance Method Summary collapse
Class Method Details
.find_by_house ⇒ Object
(key, operator, value)
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/foreman_datacenter/site.rb', line 39 def self.find_by_house#(key, operator, value) Site.includes(:racks) .group(['sites.id', 'racks.site_id']) .order('COUNT(racks.id) DESC') .references(:racks) # User.includes(:offers, :wards) # .group(['user.id', 'offers.id']) # .order('COUNT(offers.id) DESC') # .references(:offers) # conditions = sanitize_sql_for_conditions(["racks.id #{operator} ?", value_to_sql(operator, value)]) # owners = Site.joins(:racks).where(conditions).select('site.id').map(&:id) # { :conditions => "site.id IN(#{owners.join(',')})" } # { :conditions => "SELECT count(*) FROM 'sites' INNER JOIN 'racks' ON 'racks'.'site_id' = 'sites'.'id' GROUP BY site_id UNION ALL SELECT count (*) from 'racks' WHERE 'site_id' = NULL" } { :conditions => "SELECT count(*) FROM 'sites' INNER JOIN 'racks' ON 'racks'.'site_id' = 'sites'.'id' GROUP BY site_id UNION ALL SELECT count (*) from 'racks' WHERE 'site_id' = NULL ORDER BY count(*)" } end |
Instance Method Details
#devices_count ⇒ Object
33 34 35 36 37 |
# File 'app/models/foreman_datacenter/site.rb', line 33 def devices_count @devices_count ||= self.class.where(id: id). joins(racks: :devices). count end |
#rack_groups_count ⇒ Object
29 30 31 |
# File 'app/models/foreman_datacenter/site.rb', line 29 def rack_groups_count @rack_groups_count ||= rack_groups.count end |
#racks_count ⇒ Object
25 26 27 |
# File 'app/models/foreman_datacenter/site.rb', line 25 def racks_count @racks_count ||= racks.count end |