-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new base_query_class arg for associations. Fixes #85
- Loading branch information
Showing
6 changed files
with
110 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateTransactions::V20240224173636 < Avram::Migrator::Migration::V1 | ||
def migrate | ||
create table_for(Transaction) do | ||
primary_key id : Int64 | ||
add_timestamps | ||
add type : Int32 | ||
add soft_deleted_at : Time? | ||
add_belongs_to user : User, on_delete: :cascade | ||
end | ||
end | ||
|
||
def rollback | ||
drop table_for(Transaction) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class TransactionFactory < BaseFactory | ||
def initialize | ||
before_save do | ||
if operation.user_id.value.nil? | ||
user(UserFactory.create) | ||
end | ||
end | ||
end | ||
|
||
def user(u : User) | ||
user_id(u.id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Transaction < BaseModel | ||
include Avram::SoftDelete::Model | ||
|
||
enum Type | ||
Unknown | ||
Special | ||
end | ||
|
||
table do | ||
column type : Transaction::Type = Transaction::Type::Unknown | ||
column soft_deleted_at : Time? | ||
belongs_to user : User | ||
end | ||
end | ||
|
||
class TransactionQuery < Transaction::BaseQuery | ||
include Avram::SoftDelete::Query | ||
|
||
def initialize | ||
defaults &.only_kept | ||
end | ||
|
||
def special | ||
type(Transaction::Type::Special) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters