提交 08ef06db 编写于 作者: A Aaron Patterson

just return the record from insert_record, use truthiness for comparisons

上级 2b4de662
...@@ -26,14 +26,14 @@ def size ...@@ -26,14 +26,14 @@ def size
def insert_record(record, force = true, validate = true) def insert_record(record, force = true, validate = true)
if record.new_record? if record.new_record?
return false unless save_record(record, force, validate) return unless save_record(record, force, validate)
end end
through_association = @owner.send(@reflection.through_reflection.name) through_association = @owner.send(@reflection.through_reflection.name)
through_association.create!(construct_join_attributes(record)) through_association.create!(construct_join_attributes(record))
update_counter(1) update_counter(1)
true record
end end
private private
......
...@@ -306,6 +306,8 @@ def save_collection_association(reflection) ...@@ -306,6 +306,8 @@ def save_collection_association(reflection)
records.each do |record| records.each do |record|
next if record.destroyed? next if record.destroyed?
saved = true
if autosave && record.marked_for_destruction? if autosave && record.marked_for_destruction?
association.destroy(record) association.destroy(record)
elsif autosave != false && (@new_record_before_save || record.new_record?) elsif autosave != false && (@new_record_before_save || record.new_record?)
...@@ -318,7 +320,7 @@ def save_collection_association(reflection) ...@@ -318,7 +320,7 @@ def save_collection_association(reflection)
saved = record.save(:validate => false) saved = record.save(:validate => false)
end end
raise ActiveRecord::Rollback if saved == false raise ActiveRecord::Rollback unless saved
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册