Skip to content

Commit

Permalink
Remove model association presets
Browse files Browse the repository at this point in the history
Fixes compile error resulting from including the same mixin twice:

```
There was a problem expanding macro 'setup_initialize'

Code in macro 'setup'

 1 | Avram::Model.setup_initialize(
     ^
Called macro defined in lib/avram/src/avram/model.cr:176:3

 176 | macro setup_initialize(columns, *args, **named_args)

Which expanded to:

 >  9 |           @price,
 > 10 |
 > 11 |           @credit_note_id,
                  ^
Error: duplicated def parameter name: credit_note_id
```
  • Loading branch information
akadusei committed Sep 11, 2024
1 parent f3cdd59 commit 4fb56a9
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 55 deletions.
1 change: 1 addition & 0 deletions spec/support/app/src/models/credit_note_item.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class CreditNoteItem < BaseModel
include Bill::CreditNoteItem
include Bill::BelongsToCreditNote

table :credit_note_items {}
end
1 change: 1 addition & 0 deletions spec/support/app/src/models/invoice_item.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class InvoiceItem < BaseModel
include Bill::InvoiceItem
include Bill::BelongsToInvoice

table :invoice_items {}
end
9 changes: 2 additions & 7 deletions src/bill/models/credit_note.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ module Bill::CreditNote
include Bill::ParentAmount
include Bill::ReferenceColumns

{% if Avram::Model.all_subclasses.find(&.name.== :Invoice.id) %}
include Bill::BelongsToInvoice
{% end %}

{% if Avram::Model.all_subclasses.find(&.name.== :CreditNoteItem.id) %}
include Bill::HasManyCreditNoteItems
{% end %}
# include Bill::BelongsToInvoice
# include Bill::HasManyCreditNoteItems

column description : String?
column notes : String?
Expand Down
4 changes: 1 addition & 3 deletions src/bill/models/credit_note_item.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Bill::CreditNoteItem
macro included
{% if Avram::Model.all_subclasses.find(&.name.== :CreditNote.id) %}
include Bill::BelongsToCreditNote
{% end %}
# include Bill::BelongsToCreditNote

column description : String
column quantity : Quantity
Expand Down
14 changes: 3 additions & 11 deletions src/bill/models/invoice.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@ module Bill::Invoice
include Bill::ReferenceColumns
include Bill::ParentNetAmount

{% if Avram::Model.all_subclasses.find(&.name.== :CreditNote.id) %}
include Bill::HasManyCreditNotes
{% end %}

{% if Avram::Model.all_subclasses.find(&.name.== :InvoiceItem.id) %}
include Bill::HasManyInvoiceItems
{% end %}

{% if Avram::Model.all_subclasses.find(&.name.== :User.id) %}
include Bill::BelongsToUser
{% end %}
# include Bill::BelongsToUser
# include Bill::HasManyCreditNotes
# include Bill::HasManyInvoiceItems

column business_details : String
column description : String?
Expand Down
4 changes: 1 addition & 3 deletions src/bill/models/invoice_item.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Bill::InvoiceItem
macro included
{% if Avram::Model.all_subclasses.find(&.name.== :Invoice.id) %}
include Bill::BelongsToInvoice
{% end %}
# include Bill::BelongsToInvoice

column description : String
column quantity : Quantity
Expand Down
4 changes: 1 addition & 3 deletions src/bill/models/receipt.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ module Bill::Receipt
macro included
include Bill::ReferenceColumns

{% if Avram::Model.all_subclasses.find(&.name.== :User.id) %}
include Bill::BelongsToUser
{% end %}
#include Bill::BelongsToUser

column amount : Amount
column business_details : String
Expand Down
19 changes: 4 additions & 15 deletions src/bill/models/transaction.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@ module Bill::Transaction
macro included
include Bill::ReferenceColumns

{% if Avram::Model.all_subclasses.find(&.name.== :CreditNote.id) %}
include Bill::CreditNoteTransactionSource
{% end %}

{% if Avram::Model.all_subclasses.find(&.name.== :Invoice.id) %}
include Bill::InvoiceTransactionSource
{% end %}

{% if Avram::Model.all_subclasses.find(&.name.== :Receipt.id) %}
include Bill::ReceiptTransactionSource
{% end %}

{% if Avram::Model.all_subclasses.find(&.name.== :User.id) %}
include Bill::BelongsToUser
{% end %}
# include Bill::BelongsToUser
# include Bill::CreditNoteTransactionSource
# include Bill::InvoiceTransactionSource
# include Bill::ReceiptTransactionSource

column amount : Amount
column description : String
Expand Down
16 changes: 3 additions & 13 deletions src/bill/models/user.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@ module Bill::User
abstract def billing_details : String

macro included
{% if Avram::Model.all_subclasses.find(&.name.== :CreditNote.id) %}
include Bill::HasManyCreditNotesThroughInvoices
{% end %}

{% if Avram::Model.all_subclasses.find(&.name.== :Invoice.id) %}
include Bill::HasManyInvoices
{% end %}

{% if Avram::Model.all_subclasses.find(&.name.== :Receipt.id) %}
include Bill::HasManyReceipts
{% end %}
# include Bill::HasManyCreditNotesThroughInvoices
# include Bill::HasManyInvoices
# include Bill::HasManyReceipts

{% if Avram::Model.all_subclasses.find(&.name.== :Transaction.id) %}
include Bill::HasManyTransactions

{% if Avram::Model.all_subclasses.find(&.name.== :CreditNote.id) %}
include Bill::CreditNotesAmount
{% end %}
Expand Down

0 comments on commit 4fb56a9

Please sign in to comment.