Commit d328d69d authored by Marco Sehrer's avatar Marco Sehrer
Browse files

Merge pull request #222 from ninjaconcept/222-fix-reaction-with-empty-multiselect

Reaction creation fails with empty purification & dangerous_products
parents c83a7802 59dc4759
......@@ -84,8 +84,8 @@ module Chemotion
optional :timestamp_start, type: String
optional :timestamp_stop, type: String
optional :observation, type: String
optional :purification, type: Array, default: []
optional :dangerous_products, type: Array, default: []
optional :purification, type: Array[String]
optional :dangerous_products, type: Array[String]
optional :solvents, type: String
optional :tlc_description, type: String
optional :rf_value, type: String
......@@ -125,8 +125,8 @@ module Chemotion
optional :timestamp_start, type: String
optional :timestamp_stop, type: String
optional :observation, type: String
optional :purification, type: Array, default: []
optional :dangerous_products, type: Array, default: []
optional :purification, type: Array[String]
optional :dangerous_products, type: Array[String]
optional :solvents, type: String
optional :tlc_description, type: String
optional :rf_value, type: String
......@@ -142,7 +142,14 @@ module Chemotion
# end
post do
ap params
attributes = declared(params, include_missing: false).symbolize_keys
ap attributes
materials = attributes.delete(:materials)
collection_id = attributes.delete(:collection_id)
......
......@@ -54,10 +54,12 @@ class Reaction < ActiveRecord::Base
before_destroy :destroy_associations
before_save :update_svg_file!
before_save :cleanup_array_fields
def destroy_associations
# WARNING: Using delete_all instead of destroy_all due to PG Error
# TODO: Check this error and consider another solution
# TODO: define dependent destroy hooks
Literature.where(reaction_id: id).delete_all
CollectionsReaction.where(reaction_id: id).delete_all
ReactionsProductSample.where(reaction_id: id).delete_all
......@@ -83,4 +85,9 @@ class Reaction < ActiveRecord::Base
end
end
def cleanup_array_fields
self.dangerous_products = dangerous_products.reject(&:blank?)
self.purification = purification.reject(&:blank?)
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment