Why is there no "as" for HasMany/BelongsToMany in v7? #17212
-
In v7, let's say I have the following example: @HasMany(() => PostComments, {
foreignKey: "post_id",
as: "comments",
}) I get the following:
This happens with BelongsToMany as well. Without the Why is the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Because the name of the association is also the name of the class field that will be used to access the eagerly loaded association, when using decorators, the name of the class field being decorated is automatically used as the |
Beta Was this translation helpful? Give feedback.
-
Oh, thank you! That's amazing, so if I have: @HasMany(() => PostComments, "post_id")
declare comments?: NonAttribute<PostComments[]>; It automatically knows that the "as" is "comments"! That's SO nice. |
Beta Was this translation helpful? Give feedback.
Because the name of the association is also the name of the class field that will be used to access the eagerly loaded association, when using decorators, the name of the class field being decorated is automatically used as the
as
option