Penso che si possa fare in questo modo per scopi
class User
has_many :properties
scope :max_properties,
select("users.id, count(properties.id) AS properties_count").
joins(:properties).
group("properties.id").
order("properties_count DESC").
limit(1)
scope :min_properties,
select("users.id, count(properties.id) AS properties_count").
joins(:properties).
group("properties.id").
order("properties_count ASC").
limit(1)
E basta chiamare User.max_properties e User.min_properties
aggiornamento:
Sarà aslo lavoro come Borama suggeted
class User
has_many :properties
scope :max_properties,
select("users.*, count(properties.id) AS properties_count").
joins(:properties).
group("users.id").
order("properties_count DESC").
limit(1)
scope :min_properties,
select("users.*, count(properties.id) AS properties_count").
joins(:properties).
group("users.id").
order("properties_count ASC").
limit(1)
quali proprietà min, cioè da quale campo? per favore, scrivi –