easy-admin-rails 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d516d9564b3e2e33581e101ed5f5fed1fb294407f6de918e2532a3fcef1acea5
|
4
|
+
data.tar.gz: f3f23ffc0489acddce45c29f4324d38397e088fc4b7fc872fb06ed6cf4d07c64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3632ce6f54bb99a75db6a45471f53f01eb34c132480367f84017c90ab45f4605527f2a87f89a4446e41ff3182decf590c9df0e3d6178034cc713421b41d30ff6
|
7
|
+
data.tar.gz: 20b25f16081adfd5eea8cbbf62d96c35aee0b38da356befed86132d576d20819c9985987ae1d04e557f49b61964492f2c714b1fe9dca981c4867b9dce8051d60
|
@@ -28,21 +28,50 @@ module EasyAdmin
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def load_association_record
|
31
|
-
|
31
|
+
foreign_key_value = get_foreign_key_value
|
32
|
+
return nil if foreign_key_value.blank?
|
32
33
|
|
33
34
|
association_class = determine_association
|
34
35
|
|
35
|
-
if
|
36
|
+
if foreign_key_value.respond_to?(:id)
|
36
37
|
# Already loaded record
|
37
|
-
|
38
|
+
foreign_key_value
|
38
39
|
else
|
39
40
|
# ID value, need to load the record
|
40
|
-
association_class.find_by(id:
|
41
|
+
association_class.find_by(id: foreign_key_value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_foreign_key_value
|
46
|
+
# If foreign_key is explicitly specified, use that field
|
47
|
+
if field[:foreign_key]
|
48
|
+
@record.public_send(field[:foreign_key])
|
49
|
+
elsif field[:association]
|
50
|
+
# Use Rails association reflection to get the foreign key
|
51
|
+
reflection = @record.class.reflect_on_association(field[:association])
|
52
|
+
if reflection
|
53
|
+
@record.public_send(reflection.foreign_key)
|
54
|
+
else
|
55
|
+
# Fallback to the original value (field name)
|
56
|
+
value
|
57
|
+
end
|
58
|
+
else
|
59
|
+
# Default behavior - use the field value
|
60
|
+
value
|
41
61
|
end
|
42
62
|
end
|
43
63
|
|
44
64
|
def determine_association
|
45
|
-
|
65
|
+
if field[:association]
|
66
|
+
# If association is specified, get the class from the model's reflection
|
67
|
+
association_name = field[:association].to_s
|
68
|
+
reflection = @record.class.reflect_on_association(association_name)
|
69
|
+
if reflection
|
70
|
+
return reflection.klass
|
71
|
+
else
|
72
|
+
raise ArgumentError, "Association '#{association_name}' not found on #{@record.class}"
|
73
|
+
end
|
74
|
+
end
|
46
75
|
|
47
76
|
# Try to determine from attribute name
|
48
77
|
if field_name.to_s.end_with?('_id')
|
@@ -28,7 +28,7 @@ module EasyAdmin
|
|
28
28
|
|
29
29
|
def render_field_value
|
30
30
|
# Use the existing field rendering logic from the Rails views
|
31
|
-
field_value =
|
31
|
+
field_value = get_field_value
|
32
32
|
|
33
33
|
# Use the same render_field helper that the ERB templates use
|
34
34
|
unsafe_raw render_field(
|
@@ -38,6 +38,15 @@ module EasyAdmin
|
|
38
38
|
record: @record
|
39
39
|
)
|
40
40
|
end
|
41
|
+
|
42
|
+
def get_field_value
|
43
|
+
# For belongs_to fields, use the association name if specified
|
44
|
+
if @field_config[:type] == :belongs_to && @field_config[:association]
|
45
|
+
@record.public_send(@field_config[:association])
|
46
|
+
else
|
47
|
+
@record.public_send(@field_config[:name])
|
48
|
+
end
|
49
|
+
end
|
41
50
|
|
42
51
|
def render_inline_edit_trigger
|
43
52
|
div do
|
data/lib/easy_admin/resource.rb
CHANGED
@@ -56,7 +56,9 @@ module EasyAdmin
|
|
56
56
|
suggest: options[:suggest], # for dynamic option loading
|
57
57
|
display_method: options[:display_method], # for association fields
|
58
58
|
help_text: options[:help_text],
|
59
|
-
editable: options[:editable]
|
59
|
+
editable: options[:editable],
|
60
|
+
association: options[:association],
|
61
|
+
foreign_key: options[:foreign_key] # for belongs_to fields
|
60
62
|
}]
|
61
63
|
end
|
62
64
|
|
@@ -321,7 +323,9 @@ module EasyAdmin
|
|
321
323
|
multiple: options[:multiple],
|
322
324
|
placeholder: options[:placeholder],
|
323
325
|
help_text: options[:help_text],
|
324
|
-
editable: options[:editable]
|
326
|
+
editable: options[:editable],
|
327
|
+
association: options[:association],
|
328
|
+
foreign_key: options[:foreign_key]
|
325
329
|
}
|
326
330
|
|
327
331
|
if @current_tab
|
data/lib/easy_admin/version.rb
CHANGED