Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Report < ActiveRecord::Base
- has_many :report_parameters
- has_many :parameters, :through => :report_parameters do
- def push_with_attributes(monitored_parameter, rich_join_attributes)
- ReportParameter.send(:with_scope, :create => rich_join_attributes) { self << monitored_parameter }
- end
- end
- # "report_parameter_attributes"=>[{"value"=>"10", "parameter_id"=>"14"}]
- def report_parameter_attributes=(parameter_attributes)
- parameters.clear
- parameter_attributes.each do |attributes|
- parameters.push_with_attributes(Parameter.find(attributes[:parameter_id].to_i), { :value => attributes[:value] })
- end
- end
- end
- # if self(Report) is a new record join attribute is not stored upon creation.
- # 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)
- # on update:
- # 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