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

20 views
Skip to first unread message

Idan Attias

unread,
May 10, 2017, 7:56:25 AM5/10/17
to Ruby on Rails: Core
Hi,

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?

Thanks,
Idan.

Andrew Kaspick

unread,
May 10, 2017, 9:58:49 AM5/10/17
to Ruby on Rails: Core
Use transactions http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html directly.  Also, you can't have hashes with keys of the same name.



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages