不要怂,就是干,撸起袖子干!

Commit 03bed433 by Andrew Hookom Committed by Jan Aagaard Meier

'clarifying the return value of findOrCreate' (#7494)

* 'clarifying the return value of findOrCreate'

The documentation of findOrCreate previously had no precise indication of what to expect findOrCreate to return. I added that it returns an array with two parts in the comments that had already existed in the examples.

* minor typo fixes

* Made some wording changes for tense
1 parent a0bca973
Showing with 13 additions and 6 deletions
...@@ -43,14 +43,18 @@ User ...@@ -43,14 +43,18 @@ User
console.log(created) console.log(created)
/* /*
{ findOrCreate returns an array containing the object that was found or created and a boolean that will be true if a new object was created and false if not, like so:
[ {
username: 'sdepold', username: 'sdepold',
job: 'Technical Lead JavaScript', job: 'Technical Lead JavaScript',
id: 1, id: 1,
createdAt: Fri Mar 22 2013 21: 28: 34 GMT + 0100(CET), createdAt: Fri Mar 22 2013 21: 28: 34 GMT + 0100(CET),
updatedAt: Fri Mar 22 2013 21: 28: 34 GMT + 0100(CET) updatedAt: Fri Mar 22 2013 21: 28: 34 GMT + 0100(CET)
} },
created: true true ]
In the example above, the "spread" on line 39 divides the array into its 2 parts and passes them as arguments to the callback function defined beginning at line 39, which treats them as "user" and "created" in this case. (So "user" will be the object from index 0 of the returned array and "created" will equal "true".)
*/ */
}) })
``` ```
...@@ -69,14 +73,17 @@ User ...@@ -69,14 +73,17 @@ User
console.log(created) console.log(created)
/* /*
{ In this example, findOrCreate returns an array like this:
[ {
username: 'fnord', username: 'fnord',
job: 'omnomnom', job: 'omnomnom',
id: 2, id: 2,
createdAt: Fri Mar 22 2013 21: 28: 34 GMT + 0100(CET), createdAt: Fri Mar 22 2013 21: 28: 34 GMT + 0100(CET),
updatedAt: Fri Mar 22 2013 21: 28: 34 GMT + 0100(CET) updatedAt: Fri Mar 22 2013 21: 28: 34 GMT + 0100(CET)
} },
created: false false
]
The array returned by findOrCreate gets spread into its 2 parts by the "spread" on line 69, and the parts will be passed as 2 arguments to the callback function beginning on line 69, which will then treat them as "user" and "created" in this case. (So "user" will be the object from index 0 of the returned array and "created" will equal "false".)
*/ */
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!