Guest User

Untitled

a guest
Feb 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. class Report < ActiveRecord::Base
  2.  
  3. has_many :report_parameters
  4. has_many :parameters, :through => :report_parameters do
  5. def push_with_attributes(monitored_parameter, rich_join_attributes)
  6. ReportParameter.send(:with_scope, :create => rich_join_attributes) { self << monitored_parameter }
  7. end
  8. end
  9.  
  10. # "report_parameter_attributes"=>[{"value"=>"10", "parameter_id"=>"14"}]
  11. def report_parameter_attributes=(parameter_attributes)
  12. parameters.clear
  13. parameter_attributes.each do |attributes|
  14. parameters.push_with_attributes(Parameter.find(attributes[:parameter_id].to_i), { :value => attributes[:value] })
  15. end
  16. end
  17.  
  18. end
  19.  
  20. # if self(Report) is a new record join attribute is not stored upon creation.
  21. # INSERT INTO `report_parameters` (`created_at`, `updated_at`, `report_id`, `value`, `parameter_id`) VALUES('2008-09-03 16:59:42', '2008-09-03 16:59:42', 5, NULL, 1)
  22.  
  23. # on update:
  24. # INSERT INTO `report_parameters` (`created_at`, `updated_at`, `report_id`, `value`, `parameter_id`) VALUES('2008-09-03 17:00:06', '2008-09-03 17:00:06', 5, 'no', 1)
Add Comment
Please, Sign In to add comment