Skip to content

Commit 5a66208

Browse files
Fix dirty tracking compilation error
- Removed override of from_rs in dirty module (was causing previous_def error) - Added hook in columns.cr from_rs method to call capture_original_attributes - This allows dirty tracking to capture state after loading from database
1 parent be8baba commit 5a66208

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ development_dependencies:
2727
version: ~> 0.29.0
2828
ameba:
2929
github: crystal-ameba/ameba
30-
version: ~> 1.5.0
30+
version: ~> 1.6.4

src/granite/columns.cr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ module Granite::Columns
5757
end
5858
end
5959
{% end %}
60+
61+
# Hook for dirty tracking if included
62+
if responds_to?(:capture_original_attributes)
63+
capture_original_attributes
64+
end
6065
end
6166

6267
# Defines a column *decl* with the given *options*.

src/granite/dirty.cr

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ module Granite::Dirty
1515
@[YAML::Field(ignore: true)]
1616
@previous_changes = {} of String => Tuple(Granite::Columns::Type, Granite::Columns::Type)
1717

18-
# Override from_rs to capture original state
19-
def from_rs(result : DB::ResultSet) : Nil
20-
previous_def
21-
capture_original_attributes
22-
end
18+
# We'll hook into from_rs after it's defined by overriding it later
2319

2420
# Override initialize to set up tracking for new records
2521
def initialize(**args)
@@ -184,4 +180,5 @@ module Granite::Dirty
184180
\{% end %}
185181
end
186182
end
183+
187184
end

0 commit comments

Comments
 (0)