Skip to content

Commit

Permalink
fix: add missing fields to 'FindOrCreateType' (#12338)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonirico committed Jun 7, 2020
1 parent f367191 commit 72925cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
7 changes: 3 additions & 4 deletions types/lib/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,11 @@ export interface Hookable {
/**
* Options for Model.findOrCreate method
*/
export interface FindOrCreateOptions extends Logging, Transactionable {
export interface FindOrCreateOptions extends Filterable, Logging, Transactionable {
/**
* A hash of search attributes.
* The fields to insert / update. Defaults to all fields
*/
where: WhereOptions;

fields?: string[];
/**
* Default values to use if building a new instance
*/
Expand Down
20 changes: 17 additions & 3 deletions types/test/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ UserModel.findCreateFind({
}
})

/**
* Tests for findOrCreate() type.
*/

UserModel.findOrCreate({
fields: [ "jane.doe" ],
where: {
username: "jane.doe"
},
defaults: {
username: "jane.doe"
}
})

/**
* Test for primaryKeyAttributes.
*/
Expand All @@ -116,12 +130,12 @@ someInstance.getOthers({
joinTableAttributes: { include: [ 'id' ] }
})

/**
/**
* Test for through options in creating a BelongsToMany association
*/
class Film extends Model {}

class Actor extends Model {}
class Actor extends Model {}

Film.belongsToMany(Actor, {
through: {
Expand All @@ -135,4 +149,4 @@ Actor.belongsToMany(Film, {
model: 'FilmActors',
paranoid: true
}
})
})

0 comments on commit 72925cf

Please sign in to comment.