aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/association_basics.md
diff options
context:
space:
mode:
authorankit1910 <ankit.bansal@vinsol.com>2015-06-21 22:32:52 +0530
committerankit1910 <ankit.bansal@vinsol.com>2015-06-21 22:32:52 +0530
commit8f6e0b71b00b3c66ca10aaed9fb1e0201c353938 (patch)
tree6ebc38b799ca42ce60f467d9b9dcfbe918067380 /guides/source/association_basics.md
parent29959eb59da3cedee71d29fe84e82cfa71ad4cf3 (diff)
downloadrails-8f6e0b71b00b3c66ca10aaed9fb1e0201c353938.tar.gz
rails-8f6e0b71b00b3c66ca10aaed9fb1e0201c353938.tar.bz2
rails-8f6e0b71b00b3c66ca10aaed9fb1e0201c353938.zip
Change documentation for collection.build and collection.create [ci-skip]
Diffstat (limited to 'guides/source/association_basics.md')
-rw-r--r--guides/source/association_basics.md14
1 files changed, 12 insertions, 2 deletions
diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md
index 05dd0d2a04..0f909e9861 100644
--- a/guides/source/association_basics.md
+++ b/guides/source/association_basics.md
@@ -1519,20 +1519,30 @@ conditions exists in the collection. It uses the same syntax and options as
##### `collection.build(attributes = {}, ...)`
-The `collection.build` method returns one or more new objects of the associated type. These objects will be instantiated from the passed attributes, and the link through their foreign key will be created, but the associated objects will _not_ yet be saved.
+The `collection.build` method returns a single or array of new objects of the associated type. The object(s) will be instantiated from the passed attributes, and the link through their foreign key will be created, but the associated objects will _not_ yet be saved.
```ruby
@order = @customer.orders.build(order_date: Time.now,
order_number: "A12345")
+
+@orders = @customer.orders.build([
+ { order_date: Time.now, order_number: "A12346" },
+ { order_date: Time.now, order_number: "A12347" }
+])
```
##### `collection.create(attributes = {})`
-The `collection.create` method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be created, and, once it passes all of the validations specified on the associated model, the associated object _will_ be saved.
+The `collection.create` method returns a single or array of new objects of the associated type. The object(s) will be instantiated from the passed attributes, the link through its foreign key will be created, and, once it passes all of the validations specified on the associated model, the associated object _will_ be saved.
```ruby
@order = @customer.orders.create(order_date: Time.now,
order_number: "A12345")
+
+@orders = @customer.orders.create([
+ { order_date: Time.now, order_number: "A12346" },
+ { order_date: Time.now, order_number: "A12347" }
+])
```
##### `collection.create!(attributes = {})`