18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/models/update_time.rb', line 18
def find_or_create(datasource,datatype)
if(datasource.is_a?(Class))
datasource_type = datasource.name
findconditions = {:datasource_type => datasource_type,:datasource_id => 0, :datatype => datatype}
createoptions = {:datasource_type => datasource_type, :datasource_id => 0, :datatype => datatype}
else
datasource_type = datasource.class.name
findconditions = {:datasource_type => datasource_type,:datasource_id => datasource.id, :datatype => datatype}
createoptions = {:datasource => datasource, :datatype => datatype}
end
find_object = self.find(:first, :conditions => findconditions)
if(find_object.nil?)
find_object = create(createoptions)
end
return find_object
end
|