Skip to content
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

Feasibility of filtering via many2many relationships #6

Open
addshore opened this issue Aug 18, 2023 · 0 comments
Open

Feasibility of filtering via many2many relationships #6

addshore opened this issue Aug 18, 2023 · 0 comments

Comments

@addshore
Copy link
Contributor

I'm fairly new to gorm, and only looked at this library in the past hour.

I have a set of models which I have included some simplified versions of below.
How feasible might it be to add functionality to this library that would allow filtering by User.Email when querying for a list of Devices via the Device.Users many2many relationship?
Does the library currently have any support for filtering via relationships?

type Device struct {
    ID int32  `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id" filter:"param:id;searchable;filterable"`
    Users              []*User       `gorm:"many2many:userDevice;foreignKey:id;joinForeignKey:deviceId;References:id;JoinReferences:userId"`
}

type UserDevice struct {
	ID       int32  `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
	DeviceID *int32 `gorm:"column:deviceId;type:int;uniqueIndex:uniqueEntry,priority:3;index:deviceUser,priority:1" json:"deviceId"`
	UserID   *int32 `gorm:"column:userId;type:int;uniqueIndex:uniqueEntry,priority:1;index:deviceUser,priority:2" json:"userId"`
}

type User struct {
	ID                       int32      `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
	Email                    string     `gorm:"column:email;type:varchar(512);not null;uniqueIndex:uniqueemail,priority:1" json:"email"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant