fixjour 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fixjour/definitions.rb +8 -7
- metadata +1 -1
data/lib/fixjour/definitions.rb
CHANGED
@@ -31,19 +31,20 @@ module Fixjour
|
|
31
31
|
end
|
32
32
|
}
|
33
33
|
|
34
|
-
record.class.reflect_on_all_associations(:has_one).each(&transfer_singular_ids)
|
35
|
-
record.class.reflect_on_all_associations(:belongs_to).each(&transfer_singular_ids)
|
36
|
-
|
37
34
|
transfer_plural_ids = proc { |reflection|
|
38
|
-
|
35
|
+
associated = record.send(reflection.name)
|
36
|
+
if associated.length > 0
|
39
37
|
associated.each { |rec| rec.new_record? && rec.save! }
|
40
|
-
key = reflection.options[:foreign_key] || reflection.name.to_s
|
41
|
-
|
38
|
+
key = (reflection.options[:foreign_key] || reflection.name).to_s
|
39
|
+
key.gsub!(/_ids?$/, '')
|
40
|
+
valid_attributes[key.singularize + '_ids'] = associated.map(&:id)
|
42
41
|
valid_attributes.delete(reflection.name)
|
43
42
|
end
|
44
43
|
}
|
45
44
|
|
46
|
-
|
45
|
+
builder.klass.reflect_on_all_associations(:has_one).each(&transfer_singular_ids)
|
46
|
+
builder.klass.reflect_on_all_associations(:belongs_to).each(&transfer_singular_ids)
|
47
|
+
builder.klass.reflect_on_all_associations(:has_many).each(&transfer_plural_ids)
|
47
48
|
|
48
49
|
valid_attributes.stringify_keys!
|
49
50
|
valid_attributes.make_indifferent!
|