MCPcopy Create free account
hub / github.com/axe-api/axe-api / hasMany

Method hasMany

packages/axe-api/src/Model.ts:289–313  ·  view source on GitHub ↗

* Model relationship definition. Axe API creates `hasMany` routes automatically. * * @example * get relationName() { * return this.hasMany("Post", "id", "user_id") * } * @type {Array } * @tutorial https://axe-api.com/learn/routing.html#model-relations

(
    relatedModel: string,
    primaryKey = "id",
    foreignKey = "",
    options?: Partial<IHasManyOptions>,
  )

Source from the content-addressed store, hash-verified

287 * @tutorial https://axe-api.com/learn/routing.html#model-relations
288 */
289 hasMany(
290 relatedModel: string,
291 primaryKey = "id",
292 foreignKey = "",
293 options?: Partial<IHasManyOptions>,
294 ): IRelation {
295 if (!foreignKey) {
296 const currentModelName = pluralize.singular(
297 this.constructor.name.toLowerCase(),
298 );
299 foreignKey = `${currentModelName}_id`;
300 }
301
302 return {
303 name: relatedModel,
304 type: Relationships.HAS_MANY,
305 model: relatedModel,
306 primaryKey,
307 foreignKey,
308 options: {
309 ...DEFAULT_HASH_MANY_OPTIONS,
310 ...options,
311 },
312 };
313 }
314
315 /**
316 * Model relationship definition.

Callers 15

Model.spec.tsFile · 0.80
postsMethod · 0.80
loginsMethod · 0.80
commentsMethod · 0.80
likesMethod · 0.80
childrenMethod · 0.80
postsMethod · 0.80
ownedPostsMethod · 0.80
suggestedPostsMethod · 0.80
lessonsMethod · 0.80
categoriesMethod · 0.80
permissionsMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected