Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def insert!(model, attributes={})
- attributes = attributes.stringify_keys
- begin
- record = model.new {|r| r.send(:attributes=, attributes, false) }
- def record.callback(*args)
- # inhibit all callbacks
- end
- record.save(false)
- rescue ActiveRecord::StatementInvalid
- if $!.message =~ /Column '(.+?)' cannot be null/
- unless attributes.key?($1)
- attributes[$1] = record.column_for_attribute($1).number? ? 0 : ""
- retry
- end
- end
- raise
- end
- return record
- end
Add Comment
Please, Sign In to add comment