[Feature Idea] Allow passing options to ActiveRecord::Persistence#create


I thought that since this method accepts Hash / Array as objects to be created, it can be useful to pass options too (mostly when passing array)

for example, “Model.create([{name: ‘a’, name: ‘b’}], transaction: true)” can create all objects or none of them.

another example is passing shared attributes between all objects to be created “Model.create([{name: ‘a’, name: ‘b’}], transaction: true, share: { status: 'pending '})” will create two new records in pending status(using merge).

I guess more useful options exist.

Its important to make it clear that although I suggest changing the method’s signature, It has backward compatibility.

new method signature: “create(attributes = nil, opts = {}, &block)”

Does anyone think this feature can be useful?



Use transactions http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html directly. Also, you can’t have hashes with keys of the same name.