<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,7 @@
 *SVN*
 
+* Added block-setting of attributes for Base.create like Base.new already has (Adam Meehan) [#39]
+
 * Fixed that pessimistic locking you reference the quoted table name (Josh Susser) [#67]
 
 * Fixed that change_column should be able to use :null =&gt; true on a field that formerly had false [Nate Wiger] [#26]</diff>
      <filename>activerecord/CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -603,13 +603,25 @@ module ActiveRecord #:nodoc:
       # ==== Examples
       #   # Create a single new object
       #   User.create(:first_name =&gt; 'Jamie')
+      #
       #   # Create an Array of new objects
       #   User.create([{:first_name =&gt; 'Jamie'}, {:first_name =&gt; 'Jeremy'}])
-      def create(attributes = nil)
+      #
+      #   # Create a single object and pass it into a block to set other attributes.
+      #   User.create(:first_name =&gt; 'Jamie') do |u|
+      #     u.is_admin = false
+      #   end
+      #
+      #   # Creating an Array of new objects using a block, where the block is executed for each object:
+      #   User.create([{:first_name =&gt; 'Jamie'}, {:first_name =&gt; 'Jeremy'}]) do |u|
+      #     u.is_admin = false
+      #   end 
+      def create(attributes = nil, &amp;block)
         if attributes.is_a?(Array)
-          attributes.collect { |attr| create(attr) }
+          attributes.collect { |attr| create(attr, &amp;block) }
         else
           object = new(attributes)
+          yield(object) if block_given?
           object.save
           object
         end</diff>
      <filename>activerecord/lib/active_record/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -873,11 +873,12 @@ module ActiveRecord
 
       # Creates an object just like Base.create but calls save! instead of save
       # so an exception is raised if the record is invalid.
-      def create!(attributes = nil)
+      def create!(attributes = nil, &amp;block)
         if attributes.is_a?(Array)
-          attributes.collect { |attr| create!(attr) }
+          attributes.collect { |attr| create!(attr, &amp;block) }
         else
           object = new(attributes)
+          yield(object) if block_given?
           object.save!
           object
         end</diff>
      <filename>activerecord/lib/active_record/validations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -251,6 +251,27 @@ class BasicsTest &lt; ActiveRecord::TestCase
     topic = Topic.create(&quot;title&quot; =&gt; &quot;New Topic&quot;)
     topicReloaded = Topic.find(topic.id)
     assert_equal(topic, topicReloaded)
+  end  
+
+  def test_create_through_factory_with_block
+    topic = Topic.create(&quot;title&quot; =&gt; &quot;New Topic&quot;) do |t|
+      t.author_name = &quot;David&quot;
+    end
+    topicReloaded = Topic.find(topic.id)
+    assert_equal(&quot;New Topic&quot;, topic.title)
+    assert_equal(&quot;David&quot;, topic.author_name)
+  end
+
+  def test_create_many_through_factory_with_block
+    topics = Topic.create([ { &quot;title&quot; =&gt; &quot;first&quot; }, { &quot;title&quot; =&gt; &quot;second&quot; }]) do |t|
+      t.author_name = &quot;David&quot;
+    end
+    assert_equal 2, topics.size
+    topic1, topic2 = Topic.find(topics[0].id), Topic.find(topics[1].id)
+    assert_equal &quot;first&quot;, topic1.title
+    assert_equal &quot;David&quot;, topic1.author_name
+    assert_equal &quot;second&quot;, topic2.title
+    assert_equal &quot;David&quot;, topic2.author_name
   end
 
   def test_update</diff>
      <filename>activerecord/test/cases/base_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -133,6 +133,22 @@ class ValidationsTest &lt; ActiveRecord::TestCase
       Reply.create!([ { &quot;title&quot; =&gt; &quot;OK&quot; }, { &quot;title&quot; =&gt; &quot;Wrong Create&quot; }])
     end
   end
+  
+  def test_exception_on_create_bang_with_block
+    assert_raises(ActiveRecord::RecordInvalid) do
+      Reply.create!({ &quot;title&quot; =&gt; &quot;OK&quot; }) do |r|
+        r.content = nil
+      end
+    end
+  end
+  
+  def test_exception_on_create_bang_many_with_block
+    assert_raises(ActiveRecord::RecordInvalid) do
+      Reply.create!([{ &quot;title&quot; =&gt; &quot;OK&quot; }, { &quot;title&quot; =&gt; &quot;Wrong Create&quot; }]) do |r|
+        r.content = nil
+      end
+    end
+  end
 
   def test_scoped_create_without_attributes
     Reply.with_scope(:create =&gt; {}) do</diff>
      <filename>activerecord/test/cases/validations_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>c83f75812ef89aea1b8d138aebec25de8057f156</id>
    </parent>
  </parents>
  <author>
    <name>David Heinemeier Hansson</name>
    <email>david@loudthinking.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/dd120ede53eaf71dee76894998a81626b7a689fc</url>
  <id>dd120ede53eaf71dee76894998a81626b7a689fc</id>
  <committed-date>2008-04-30T21:14:32-07:00</committed-date>
  <authored-date>2008-04-30T21:14:32-07:00</authored-date>
  <message>Added block-setting of attributes for Base.create like Base.new already has (Adam Meehan) [#39 state:resolved]</message>
  <tree>f9bcc98eba07ebfdb662489321b4e1d184020f57</tree>
  <committer>
    <name>David Heinemeier Hansson</name>
    <email>david@loudthinking.com</email>
  </committer>
</commit>
