diff options
author | Christoph Helma <helma@in-silico.ch> | 2015-07-22 20:08:12 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2015-07-22 20:08:12 +0200 |
commit | cd1cba67830505cd2d23ec83e64c0beed42a9f28 (patch) | |
tree | 23da8b4f04549afe61403fc419152cb3fd51c876 /lib/data_entry.rb | |
parent | e797fda1f946490d288e0ea7fd4eaf58eb18a746 (diff) |
mongo batch import workaround
Diffstat (limited to 'lib/data_entry.rb')
-rw-r--r-- | lib/data_entry.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/data_entry.rb b/lib/data_entry.rb new file mode 100644 index 0000000..9f6e786 --- /dev/null +++ b/lib/data_entry.rb @@ -0,0 +1,36 @@ +module OpenTox + + class DataEntry + #field :feature_id, type: BSON::ObjectId + #field :compound_id, type: BSON::ObjectId + # Kludge because csv import removes type information + field :feature_id, type: String + field :compound_id, type: String + field :value + field :warnings, type: String + field :unit, type: String + store_in collection: "data_entries" + + # preferred method for the insertion of data entries + # @example DataEntry.find_or_create compound,feature,value + # @param compound [OpenTox::Compound] + # @param feature [OpenTox::Feature] + # @param value + def self.find_or_create compound, feature, value + self.find_or_create_by( + :compound_id => compound.id, + :feature_id => feature.id, + :value => value + ) + end + + # preferred method for accessing values + # @example DataEntry[compound,feature] + # @param compound [OpenTox::Compound] + # @param feature [OpenTox::Feature] + # @return value + def self.[](compound,feature) + self.where(:compound_id => compound.id.to_s, :feature_id => feature.id.to_s).distinct(:value).first + end + end +end |