Ash Aggregates - sum Resource.field is not aggregatable

I have this Resource and i want to do an aggregate, but it always throws this error:

 aggregates -> taken_slots:
  NoSpark.Builder.Din.modules is not aggregatable

Here’s my resource:

defmodule NoSpark.Builder.Din do
  use Ash.Resource,
    data_layer: AshSqlite.DataLayer

  sqlite do
    table "dins"
    repo NoSpark.Repo
  end

  attributes do
    uuid_primary_key :id

    attribute :label, :string
    attribute :description, :string

    attribute :slots, :integer do
      allow_nil? false
      constraints min: 0
    end
  end

  relationships do
    has_many :modules, NoSpark.Builder.DinModule
  end

  aggregates do
    sum :taken_slots, [:modules], :slots
  end

  calculations do
    calculate :free_slots, :integer do
      load :modules
      calculation expr(slots - taken_slots)
    end
  end
end

I’ve tried just making a calculation expr(slots - sum(modules, field: slots)) but it’s not allowed in Sqlite.

Here is my DinModule Resource:

defmodule NoSpark.Builder.DinModule do
  use Ash.Resource,
    data_layer: AshSqlite.DataLayer

  sqlite do
    table "din_modules"
    repo NoSpark.Repo
  end

  attributes do
    uuid_primary_key :id

    attribute :label, :string
    attribute :description, :string

    attribute :slots, :integer do
      allow_nil? false
      constraints min: 0
    end
  end

  relationships do
    belongs_to :module, NoSpark.Builder.Module do
      allow_nil? false
      attribute_writable? true
    end

    belongs_to :din, NoSpark.Builder.Din do
      allow_nil? false
      attribute_writable? true
    end
  end
 # trunacted...
end

Tried looking at the docs but can’t find anything? Please help :slight_smile:

Unfortunately, the SQLite Datalayer does not support aggregates at the moment.

Ahh ok, this is good to know! :slight_smile: