Fix up models to use Rails4 find_or_create - warvox - Unnamed repository; edit … | |
Log | |
Files | |
Refs | |
README | |
--- | |
commit 9daf341c542e2c723c6db741e469251e30768597 | |
parent 8a22b69da25c48aad0b9e211278a787d93419e7b | |
Author: HD Moore <[email protected]> | |
Date: Sat, 25 Oct 2014 11:37:48 -0500 | |
Fix up models to use Rails4 find_or_create | |
Diffstat: | |
M app/models/call.rb | 8 ++++---- | |
M app/models/line.rb | 2 +- | |
2 files changed, 5 insertions(+), 5 deletions(-) | |
--- | |
diff --git a/app/models/call.rb b/app/models/call.rb | |
@@ -35,7 +35,7 @@ class Call < ActiveRecord::Base | |
def matches_all_jobs | |
# "AND (( icount(\'{#{fprint.map{|x| x.to_s}.join(",")}}\'::int[] & cal… | |
- self.find_by_sql([ | |
+ self.find_by_sql([ | |
'SELECT calls.*, ' + | |
" (( icount(?::int[] & calls.fprint::int[]) / icount(?::int[])::float )… | |
'FROM calls ' + | |
@@ -45,7 +45,7 @@ class Call < ActiveRecord::Base | |
fprint_map, | |
fprint_map, | |
self.id | |
- ]) | |
+ ]) | |
end | |
def fprint_map | |
@@ -78,7 +78,7 @@ class Call < ActiveRecord::Base | |
end | |
def media | |
- CallMedium.find_or_create_by_call_id_and_project_id(self[:id], self[:proje… | |
+ CallMedium.where(call_id: self.id, project_id: self.project_id).first_or_c… | |
end | |
def media_fields | |
@@ -86,7 +86,7 @@ class Call < ActiveRecord::Base | |
end | |
def linked_line | |
- Line.find_or_create_by_number_and_project_id(self[:number], self[:project_… | |
+ Line.where(number: self.number, project_id: self.project_id).first_or_crea… | |
end | |
def update_linked_line | |
diff --git a/app/models/line.rb b/app/models/line.rb | |
@@ -3,7 +3,7 @@ class Line < ActiveRecord::Base | |
belongs_to :project | |
def set_attribute(name, value, ctype='text/plain') | |
- la = LineAttribute.find_or_create_by_line_id_and_project_id_an… | |
+ la = LineAttribute.where(line_id: self.id, project_id: self.pr… | |
la.value = value | |
la.ctype = ctype | |
la.save |