* 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>,
)
| 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. |
no outgoing calls
no test coverage detected