Save join data with has_many :through. #7658

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@steveklabnik
Member

Fixes #5057.

If you have :conditions on a has_many :through, it does not
save the data. This patch fixes that by generating the
correct SQL.

This is based on work done by @clarkgr on #5057.

I don't have a test written, because I'm an AR noob, but you have to start somewhere...

All the existing tests pass.

@steveklabnik steveklabnik Save join data with has_many :through.
Fixes #5057.

If you have :conditions on a has_many :through, it does not
save the data. This patch fixes that by generating the
correct SQL.
8f026e1
@frodsan frodsan commented on the diff Sep 17, 2012
...lib/active_record/associations/through_association.rb
@@ -51,11 +55,14 @@ def construct_join_attributes(*records)
records.map { |record| record.class.base_class.name }
end
- if records.count == 1
- Hash[join_attributes.map { |k, v| [k, v.first] }]
- else
- join_attributes
+ join_attributes = Hash[join_attributes.map { |k, v| [k, v.first] }] if records.count == 1
@frodsan
frodsan Sep 17, 2012 Contributor

Too much whitespace

@steveklabnik
steveklabnik Sep 17, 2012 Member

dammit. I will fix this if we decide that #7661 is not an actual solution.

@steveklabnik
Member

Closing: #5057 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment