diff --git a/app/models/budget/ballot/line.rb b/app/models/budget/ballot/line.rb index 23c6aaef2..0b56716c6 100644 --- a/app/models/budget/ballot/line.rb +++ b/app/models/budget/ballot/line.rb @@ -2,7 +2,7 @@ class Budget class Ballot class Line < ActiveRecord::Base belongs_to :ballot - belongs_to :investment + belongs_to :investment, counter_cache: :ballot_lines_count belongs_to :heading belongs_to :group belongs_to :budget diff --git a/db/migrate/20170428111355_add_ballot_line_count_to_investments.rb b/db/migrate/20170428111355_add_ballot_line_count_to_investments.rb new file mode 100644 index 000000000..a864075a8 --- /dev/null +++ b/db/migrate/20170428111355_add_ballot_line_count_to_investments.rb @@ -0,0 +1,5 @@ +class AddBallotLineCountToInvestments < ActiveRecord::Migration + def change + add_column :budget_investments, :ballot_lines_count, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index a8b496dee..4dc2fb2c4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170427145845) do +ActiveRecord::Schema.define(version: 20170428111355) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -144,6 +144,7 @@ ActiveRecord::Schema.define(version: 20170427145845) do t.string "location" t.string "organization_name" t.datetime "unfeasible_email_sent_at" + t.integer "ballot_lines_count", default: 0 end add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree