upgrade pat3

This commit is contained in:
2013-12-21 16:46:07 +01:00
parent b4c4a15e60
commit c6f790eccd
12 changed files with 124 additions and 80 deletions
+10 -5
View File
@@ -56,21 +56,26 @@ class Table
if tables.is_a?(Array)
lists = List.active_for_table(tables.map(&:id))
for table in tables
table.active_list_id = lists.find{|l| l.table_id == table.id}.try(:id)
if list = lists.find{|l| l.table_id == table.id}
table.active_list_id = list.id
table.active_list = list
end
end
tables
else
table = tables
list = List.active_for_table(table).first
table.active_list_id = list.id if list.present?
if list = List.active_for_table(table).first
table.active_list_id = list.id
table.active_list = list
end
table
end
end
def active_list
# nil memoizing
return @active_list if @active_list_is_set
@active_list ||= self.class.database.view(List.active_by_table_id_view(key: id, include_docs: true, reduce: false, limit: 1)).try(:first)
return @active_list if @active_list || @active_list_is_set
self.active_list = self.class.database.view(List.active_by_table_id_view(key: id, include_docs: true, reduce: false, limit: 1)).try(:first)
end
def active_list=(val)