luckyframework / luckyframework/avram
Base model requires the `databaase` method....
- Dominant language
- Crystal
- Stars
- 183
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
I'm finally getting around to upgrading to Avram 1.4.0 and after updating my base model to this:
```crystal
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:
```crystal
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.
Contributor guide
Research direction
Start by reproducing the error with the BaseModel and CampaignAudienceStat definitions shown in the issue, then trace how Avram validates database methods for models and materialized views. Confirm why separate read_database and write_database methods are not accepted here, and make the expected behavior clear with a regression check or documentation update.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- crystal
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100