Ash FrameworkAF
Ash Framework3y ago
24 replies
AlecStewart1#1125

Aggregates with resource relationships

Hello!

So maybe there's something I'm not quite understanding from the documentation, but say I have a State and City. A state can have many cities, so:
relationships do
  has_many :cities, MyProject.City
end


And a city belongs to a state:
relationships do
  belongs_to :state, MyProject.State
end


Now for a state, say I want an aggregate for the number of cities in the state. Do I have an aggregates block like the following?
aggregates do
  count :number_of_cities, :cities do
    filterable? true
  end
end


Also, could this be a oneliner as just count :number_of_cities, :cities? No do ... end?

Thanks!
Was this page helpful?