daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jan 16th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # == Schema Information
  2. #
  3. # Table name: training_classes
  4. #
  5. #  id            :integer         not null, primary key
  6. #  created_at    :datetime        not null
  7. #  updated_at    :datetime        not null
  8. #
  9. class TrainingClass < ActiveRecord::Base
  10.   has_many :meetings, class_name: :ClassMeeting, foreign_key: :class_id, dependent: :destroy, inverse_of: :training_class
  11.   has_many :training_records, foreign_key: :class_id, dependent: :destroy, inverse_of: :training_class
  12.  
  13.   scope :with_date, joins("
  14.     LEFT OUTER JOIN
  15.       (#{ClassMeeting.earliest_dates.to_sql}) as class_meeting
  16.     ON class_meeting.class_id = training_classes.id
  17.   ")
  18.   default_scope with_date.order('class_meeting.start_time ASC')
  19. end
  20.  
  21. # == Schema Information
  22. #
  23. # Table name: training_records
  24. #
  25. #  id         :integer         not null, primary key
  26. #  class_id   :integer
  27. #  created_at :datetime        not null
  28. #  updated_at :datetime        not null
  29. #
  30. class TrainingRecord < ActiveRecord::Base
  31.   belongs_to :training_class, foreign_key: :class_id, inverse_of: :training_records
  32.   has_many :attendance_records, inverse_of: :training_record, dependent: :destroy
  33.   has_many :meetings, class_name: :ClassMeeting, through: :training_class # This doesn't work correctly
  34. end
  35.  
  36. # == Schema Information
  37. #
  38. # Table name: class_meetings
  39. #
  40. #  id         :integer         not null, primary key
  41. #  class_id   :integer
  42. #  start_time :datetime
  43. #  end_time   :datetime
  44. #  created_at :datetime        not null
  45. #  updated_at :datetime        not null
  46. #
  47. class ClassMeeting < ActiveRecord::Base
  48.   belongs_to :training_class, foreign_key: :class_id, inverse_of: :meetings
  49.   has_many :attendance_records, class_name: :AttendanceRecord, foreign_key: :meeting_id, dependent: :destroy
  50.   has_many :training_records, through: :training_class # This doesn't work correctly
  51.  
  52.   scope :earliest_dates, select('
  53.     class_meetings.id,
  54.     class_meetings.class_id,
  55.     MIN(class_meetings.start_time) as start_time'
  56.   ).group('class_meetings.class_id').order('class_meetings.start_time DESC')
  57. end
  58.    
  59. irb(main):004:0> ClassMeeting.first.training_records
  60.   ClassMeeting Load (0.0ms)  SELECT "class_meetings".* FROM "class_meetings" LIMIT 1
  61.   TrainingRecord Load (0.0ms)  SELECT "training_records".* FROM "training_records" INNER JOIN "training_classes" ON "training_records"."class_id" = "training_classes"."id" WHERE "training_classes"."id" = 1 ORDER BY class_meeting.start_time ASC
  62. ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: class_meeting.start_time: SELECT "training_records".* FROM "training_records" INNER JOIN "training_classes" ON "training_records"."class_id" = "training_classes"."id" WHERE "training_classes"."id" = 1 ORDER BY class_meeting.start_time ASC
  63.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.6-x86-mingw32/lib/sqlite3/database.rb:91:in `initialize'
  64.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.6-x86-mingw32/lib/sqlite3/database.rb:91:in `new'
  65.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.6-x86-mingw32/lib/sqlite3/database.rb:91:in `prepare'
  66.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/sqlite_adapter.rb:246:in `block in exec_query'
  67.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
  68.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  69.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
  70.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/sqlite_adapter.rb:242:in `exec_query'
  71.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/sqlite_adapter.rb:467:in `select'
  72.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
  73.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
  74.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/querying.rb:38:in `block in find_by_sql'
  75.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/explain.rb:40:in `logging_query_plan'
  76.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/querying.rb:37:in `find_by_sql'
  77.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/relation.rb:171:in `exec_queries'
  78.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/relation.rb:160:in `block in to_a'
  79.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/explain.rb:33:in `logging_query_plan'
  80.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/relation.rb:159:in `to_a'
  81.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/relation/finder_methods.rb:159:in `all'
  82.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/has_many_through_association.rb:173:in `find_target'
  83.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/collection_association.rb:333:in `load_target'
  84.         from c:in `load_target'
  85.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
  86.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
  87.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
  88.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
  89.         from script/rails:6:in `require'
  90.    
  91. irb(main):006:0> TrainingRecord.first.meetings      
  92.   TrainingRecord Load (0.0ms)  SELECT "training_records".* FROM "training_records" LIMIT 1
  93.   ClassMeeting Load (0.0ms)  SELECT "class_meetings".* FROM "class_meetings" INNER JOIN "training_classes" ON "class_meetings"."class_id" = "training_classes"."id" WHERE "training_classes"."id" = 23 ORDER BY class_meeting.start_time ASC
  94. ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: class_meeting.start_time: SELECT "class_meetings".* FROM "class_meetings" INNER JOIN "training_classes" ON "class_meetings"."class_id" = "training_classes"."id" WHERE "training_classes"."id" = 23 ORDER BY class_meeting.start_time ASC
  95.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.6-x86-mingw32/lib/sqlite3/database.rb:91:in `initialize'
  96.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.6-x86-mingw32/lib/sqlite3/database.rb:91:in `new'
  97.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.6-x86-mingw32/lib/sqlite3/database.rb:91:in `prepare'
  98.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/sqlite_adapter.rb:246:in `block in exec_query'
  99.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
  100.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  101.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
  102.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/sqlite_adapter.rb:242:in `exec_query'
  103.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/sqlite_adapter.rb:467:in `select'
  104.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
  105.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
  106.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/querying.rb:38:in `block in find_by_sql'
  107.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/explain.rb:40:in `logging_query_plan'
  108.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/querying.rb:37:in `find_by_sql'
  109.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/relation.rb:171:in `exec_queries'
  110.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/relation.rb:160:in `block in to_a'
  111.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/explain.rb:33:in `logging_query_plan'
  112.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/relation.rb:159:in `to_a'
  113.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/relation/finder_methods.rb:159:in `all'
  114.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/has_many_through_association.rb:173:in `find_target'
  115.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/collection_association.rb:333:in `load_target'
  116.         from c:in `load_target'
  117.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/collection_proxy.rb:87:in `method_missing'
  118.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
  119.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
  120.         from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
  121.         from script/rails:6:in `require'
  122.         from script/rails:6:in `<main>'irb(main):007:0>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top