dynamic-active-model 1.3.1 → 1.3.2
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: 1180fa600bbb8f28bf7f2be26b9150305b9fb4486c1229bbee4d1e7f2d461018
|
|
4
|
+
data.tar.gz: 95a4e5c46ae8990dcf2250fee577f2c437a2f382229077713a33ae9575576812
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 89f510068c30b03a9eb4c9d82c57dd06c052088a9314c6c135fbde78dba8586826cc2e5f99de17f1e5bd4480d2216975bc53bd13a3222fe784daee9f5c33832d
|
|
7
|
+
data.tar.gz: 21b7af7eb2804253c4b214148d23ff86fd41c6a605ef7b86e219f0d141358f10882d1a13ab02811ea0061701a7d4620ffd6e043e36982019738aafa0276f66e5
|
|
@@ -154,10 +154,20 @@ module DynamicActiveModel
|
|
|
154
154
|
relationship_name.singularize.to_sym,
|
|
155
155
|
class_name: belongs_to_model.name,
|
|
156
156
|
foreign_key: foreign_key,
|
|
157
|
-
primary_key: primary_key
|
|
157
|
+
primary_key: primary_key,
|
|
158
|
+
optional: nullable_column?(model, foreign_key)
|
|
158
159
|
)
|
|
159
160
|
end
|
|
160
161
|
|
|
162
|
+
# A nullable foreign key makes the belongs_to optional; NOT NULL makes it required,
|
|
163
|
+
# whatever belongs_to_required_by_default is set to.
|
|
164
|
+
# @param model [Class]
|
|
165
|
+
# @param column_name [String]
|
|
166
|
+
# @return [Boolean]
|
|
167
|
+
def nullable_column?(model, column_name)
|
|
168
|
+
model.columns_hash.fetch(column_name.to_s).null
|
|
169
|
+
end
|
|
170
|
+
|
|
161
171
|
# Adds a has_many relationship to a model
|
|
162
172
|
# @param relationship_name [String] Name of the relationship
|
|
163
173
|
# @param model [Class] The referenced (parent) model that gets the association
|
|
@@ -111,7 +111,7 @@ module DynamicActiveModel
|
|
|
111
111
|
def append_association!(str, assoc_type, assoc, association_options)
|
|
112
112
|
str << " #{assoc_type} #{assoc.name.inspect}"
|
|
113
113
|
association_options.compact.each do |name, value|
|
|
114
|
-
str << ", #{name}: '#{value}'"
|
|
114
|
+
str << ", #{name}: #{value.is_a?(String) ? "'#{value}'" : value.inspect}"
|
|
115
115
|
end
|
|
116
116
|
str << "\n"
|
|
117
117
|
end
|
|
@@ -141,6 +141,7 @@ module DynamicActiveModel
|
|
|
141
141
|
assoc.options[:foreign_key]
|
|
142
142
|
end
|
|
143
143
|
options[:primary_key] = assoc.options[:primary_key] unless assoc.options[:primary_key] == 'id'
|
|
144
|
+
options[:optional] = true if assoc.options[:optional]
|
|
144
145
|
options
|
|
145
146
|
end
|
|
146
147
|
|