Skip to content

Base model requires the databaase method.... #1126

Description

@jwoertink

I'm finally getting around to upgrading to Avram 1.4.0 and after updating my base model to this:

abstract class BaseModel < Avram::Model
  def self.read_database : Avram::Database.class
    AppDatabase
  end

  def self.write_database : Avram::Database.class
    AppDatabase
  end

  macro default_columns
    primary_key id : UUID
    timestamps
  end
end

I get this error:

The class method `database` must be defined on CampaignAudienceStat, the BaseModel,
       or defined as separate `read_database` and `write_database` class methods.

       Example:
         def self.database : Avram::Database.class
           AppDatabase
         end

       Or separated as:
         def self.read_database : Avram::Database.class
           ReadDatabase
         end

         def self.write_database : Avram::Database.class
           WriteDatabase
         end (Exception)

My CampaignAudienceStat model looks like this:

class CampaignAudienceStat < BaseModel
  # TODO: figure out why this is needed
  skip_schema_enforcer
  view materialized: true do
    column user_id : UUID
    column username : String
    # some other columns
  end
end

I added the self.database method back in and now it's all happy... I just don't know why.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions