1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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"
belongs_to :dataset
has_one :compound
has_one :feature
# 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
|