Skip to content

Commit

Permalink
fix(*): use Array.isArray of instanceof
Browse files Browse the repository at this point in the history
The instanceof method fails when passing data between sandboxes, for example repl to code

fix #262
  • Loading branch information
thetutlage committed Dec 14, 2017
1 parent cddb3fe commit 892208b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Database/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class DatabaseManager {
*/
close (names) {
let connections = names || _.keys(this._connectionPools)
connections = connections instanceof Array === false ? [connections] : connections
connections = !Array.isArray(connections) ? [connections] : connections
_.each(connections, (name) => {
this._connectionPools[name].close()
this._connectionPools[name] = null
Expand Down
2 changes: 1 addition & 1 deletion src/Lucid/Model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ class Model extends BaseModel {
* @throws {InvalidArgumentException} If payloadArray is not an array
*/
static async createMany (payloadArray, trx) {
if (payloadArray instanceof Array === false) {
if (!Array.isArray(payloadArray)) {
throw GE
.InvalidArgumentException
.invalidParameter(`${this.name}.createMany expects an array of values`, payloadArray)
Expand Down
2 changes: 1 addition & 1 deletion src/Lucid/QueryBuilder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class QueryBuilder {
* Don't do anything when array is empty or value is not
* an array
*/
const scopesToIgnore = scopes instanceof Array === true ? scopes : ['*']
const scopesToIgnore = Array.isArray(scopes) ? scopes : ['*']
this._ignoreScopes = this._ignoreScopes.concat(scopesToIgnore)
return this
}
Expand Down
8 changes: 4 additions & 4 deletions src/Lucid/Relations/BelongsToMany.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ class BelongsToMany extends BaseRelation {
*/
async attach (references, pivotCallback = null) {
await this._loadAndCachePivot()
const rows = references instanceof Array === false ? [references] : references
const rows = !Array.isArray(references) ? [references] : references

return Promise.all(rows.map((row) => {
const pivotInstance = this._getPivotInstance(row)
Expand Down Expand Up @@ -787,7 +787,7 @@ class BelongsToMany extends BaseRelation {
detach (references) {
const query = this.pivotQuery(false)
if (references) {
const rows = references instanceof Array === false ? [references] : references
const rows = !Array.isArray(references) ? [references] : references
query.whereIn(this.relatedForeignKey, rows)
_.remove(this._existingPivotInstances, (pivotInstance) => {
return _.includes(rows, pivotInstance[this.relatedForeignKey])
Expand Down Expand Up @@ -860,7 +860,7 @@ class BelongsToMany extends BaseRelation {
* @return {void}
*/
async saveMany (arrayOfRelatedInstances, pivotCallback) {
if (arrayOfRelatedInstances instanceof Array === false) {
if (!Array.isArray(arrayOfRelatedInstances)) {
throw GE
.InvalidArgumentException
.invalidParameter('belongsToMany.saveMany expects an array of related model instances', arrayOfRelatedInstances)
Expand Down Expand Up @@ -905,7 +905,7 @@ class BelongsToMany extends BaseRelation {
* @return {Array}
*/
async createMany (rows, pivotCallback) {
if (rows instanceof Array === false) {
if (!Array.isArray(rows)) {
throw GE
.InvalidArgumentException
.invalidParameter('belongsToMany.createMany expects an array of related model instances', rows)
Expand Down
4 changes: 2 additions & 2 deletions src/Lucid/Relations/HasMany.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class HasMany extends BaseRelation {
* @return {Array}
*/
async createMany (arrayOfPayload, trx) {
if (arrayOfPayload instanceof Array === false) {
if (!Array.isArray(arrayOfPayload)) {
throw GE
.InvalidArgumentException
.invalidParameter('hasMany.createMany expects an array of values', arrayOfPayload)
Expand All @@ -208,7 +208,7 @@ class HasMany extends BaseRelation {
* @return {Array}
*/
async saveMany (arrayOfRelatedInstances, trx) {
if (arrayOfRelatedInstances instanceof Array === false) {
if (!Array.isArray(arrayOfRelatedInstances)) {
throw GE
.InvalidArgumentException
.invalidParameter('hasMany.saveMany expects an array of related model instances', arrayOfRelatedInstances)
Expand Down

0 comments on commit 892208b

Please sign in to comment.