Created
September 3, 2008 17:01
-
-
Save masterkain/8621 to your computer and use it in GitHub Desktop.
strange behaviour on saving rich join attributes
This file contains 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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment