New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Many-to-Many Relationship #224
Comments
Is there any progress? I also encountered the same problem. |
Hi @balan05 & @Vincent1016 - sorry for not replying earlier In the current version of remult, you can do that with a 'through' table @Entity('users')
class User {
@Fields.cuid()
id = ''
@Fields.string()
name = ''
}
@Entity('UserTypes')
class UserType {
@Fields.cuid()
id = ''
@Fields.string()
name = ''
}
@Entity<UserToType>('UsersToTypes', {
id: (e) => [e.userId, e.typeId],
})
class UserToType {
@Fields.string()
userId = ''
@Fields.string()
typeId = ''
} You can employ advanced filtering techniques as detailed in: You can also add many to one relations to the mix - but in that case, at the current version, I recommend adding a separate id column for good measure @Entity<UserToType>('UsersToTypes')
class UserToType {
@Fields.cuid()
id = ''
@Field(() => User, { lazy: true //to only load when requested
})
userId!: User
@Field(() => UserType)
typeId!: UserType
} You can use We are currently planning some improvements in the relations area, stay tuned |
@noam-honig |
Hey, |
Hi @mihaa1 No, at this time we do not generate a foreign key in the db by default - we only generate the structure to store the data, and leave it to the developer to create the meta data objects such as indexes, foreign keys etc... You can easily do that as part of the version update process discussed in: |
Thanks. |
Not at this time - I enforce it in my application code, not by remult.
…On Thu, Oct 19, 2023 at 3:45 PM mihaa1 ***@***.***> wrote:
Hi @mihaa1 <https://github.com/mihaa1>
No, at this time we do not generate a foreign key in the db by default -
we only generate the structure to store the data, and leave it to the
developer to create the meta data objects such as indexes, foreign keys
etc...
You can easily do that as part of the version update process discussed in:
#162 <#162>
Thanks.
Rules of relations are enforced by code then inside remult?
e.g. creating relation with non existent id
—
Reply to this email directly, view it on GitHub
<#224 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD65PU7EDEI2HXHVE2MMOATYAEOE7AVCNFSM6AAAAAA3PBZCXCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZQHEYTGNBWGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Is your feature request related to a problem? Please describe.
I'd like to create complex relationship with through tables.
Describe the solution you'd like
Add the ability to define Many-to-Many relationships
Describe alternatives you've considered
I think its possible to define through table manually, then use the relationship definition like One-to-Many.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: