This project is archived and is in readonly mode.
Add blocks to AR create and update
-
Adam Meehan
Updated patch with conforming more to rails conventions with blocks.
-
Ken Miller
+1
-
wildchild
+1
-
matthuhiggins
Perhaps a tangent, but why not replace
object = new(attributes)
yield(object) if block_given?
object.save
object
with
returning new(attributes) do |object|
yield(object) if block_given?
object.save
end
-
Adam Meehan
Sure that would be nice. I was not sure how often 'returning' was being used in rails code. I thought of it more as for external use.
From greping the rails edge code I see there is some use of it. I am happy to change it to the returning convention if thats the way rails is going.
-
Adam Meehan
Added another patch which uses returning. I will let the core team decide what they prefer.
Thanks for the suggestion Matt.
-
matthuhiggins
Using returning reduces performance. Since create is a common operation, my suggestion might not be worth it.
-
Adam Meehan
I did wonder. I will let the core team decide based on what they know and would prefer. Both patches are there.
-
Adam Meehan
Patch updated using correct format.
-
Repository
- State changed from new to resolved
(from [dd120ede53eaf71dee76894998a81626b7a689fc]) Added block-setting of attributes for Base.create like Base.new already has (Adam Meehan) [#39 state:resolved]
-
DHH
- State changed from resolved to new
The create block is good stuff, but I don't think the update one warrants enough use to be included. Base#update is kinda suspect as is.
-
DHH
- State changed from new to resolved
-
Adam Meehan
Thanks David.
