Created
March 2, 2016 16:37
-
-
Save durexlw/0338ffeae95f2baf9c32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_table :monthly_transactions do |t| | |
t.integer :jaar | |
t.integer :maand | |
t.integer :cijfer_1 | |
t.decimal :saldo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MonthlyTransaction < ActiveRecord::Base | |
scope :saldo_per_month, -> { select( [ :jaar, :maand, MonthlyTransaction.arel_table[:saldo].sum ] ) | |
.where( | |
Arel::Nodes::Group.new( | |
MonthlyTransaction.arel_table[:cijfer_1].eq('6').or(MonthlyTransaction.arel_table[:cijfer_1].eq('7')) | |
) | |
).group(:jaar, :maand) } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MonthlyTransaction.saldo_per_month[1].saldo | |
MonthlyTransaction Load (4.9ms) SELECT "monthly_transactions"."jaar", "monthly_transactions"."maand", SUM("monthly_transactions"."saldo") FROM "monthly_transactions" WHERE (("monthly_transactions"."cijfer_1" = 6 OR "monthly_transactions"."cijfer_1" = 7)) GROUP BY "monthly_transactions"."jaar", "monthly_transactions"."maand" | |
ActiveModel::MissingAttributeError: missing attribute: saldo from /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/attribute_methods/read.rb:93:in `block in _read_attribute' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/attribute_set.rb:31:in `block in fetch_value' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/attribute.rb:150:in `value' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/attribute_set.rb:31:in `fetch_value' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/attribute_methods/read.rb:93:in `_read_attribute' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/attribute_methods.rb:50:in `__temp__3716c646f6' | |
from (irb):1 | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require' | |
from /home/ubuntu/workspace/bin/rails:8:in `<top (required)>' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `block in load' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency' | |
from /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load' | |
from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' | |
from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment