33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/models/sidebar_section.rb', line 33
def
ActiveRecord::Base.transaction do
self.update!(title: "Community")
self..destroy_all
=
SidebarUrl::COMMUNITY_SECTION_LINKS.map do |url_data|
"('#{url_data[:name]}', '#{url_data[:path]}', '#{url_data[:icon]}', '#{url_data[:segment]}', false, now(), now())"
end
result = DB.query <<~SQL
INSERT INTO sidebar_urls(name, value, icon, segment, external, created_at, updated_at)
VALUES #{.join(",")}
RETURNING sidebar_urls.id
SQL
=
result.map.with_index do |url, index|
"(-1, #{url.id}, 'SidebarUrl', #{self.id}, #{index}, now(), now())"
end
DB.query <<~SQL
INSERT INTO sidebar_section_links(user_id, linkable_id, linkable_type, sidebar_section_id, position, created_at, updated_at)
VALUES #{.join(",")}
SQL
end
end
|