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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Idan Attias
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

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



On Wed, May 10, 2017 at 3:16 AM, Idan Attias <[hidden email]> wrote:
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.