goadesign / goadesign/gorma

"Filter By" using Field Alias

Open
#168 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
141
Forks
35
PR merge metrics
No merged PRs in 30d

Description

Hello, i have a problem when after generate a gorma design:
```
Field("user_device_id", gorma.UUID, func() {
Alias("device_id")
SQLTag("type:varbinary(36)")
})
```
the result:
```
// Belongs To Relationships

// UserDeviceVerificationFilterByUserDevice is a gorm filter for a Belongs To relationship.
func UserDeviceVerificationFilterByUserDevice(userDeviceID uuid.UUID, originaldb *gorm.DB) func(db *gorm.DB) *gorm.DB {

if userDeviceID.String() != "" {

return func(db *gorm.DB) *gorm.DB {
return db.Where("user_device_id = ?", userDeviceID)

}
}
return func(db *gorm.DB) *gorm.DB { return db }
}
```
i think, when Alias is set, must create filter by "Alias", not from Table ID, like this :
```
// Belongs To Relationships

// UserDeviceVerificationFilterByUserDevice is a gorm filter for a Belongs To relationship.
func UserDeviceVerificationFilterByUserDevice(userDeviceID uuid.UUID, originaldb *gorm.DB) func(db *gorm.DB) *gorm.DB {

if userDeviceID.String() != "" {

return func(db *gorm.DB) *gorm.DB {
return db.Where("device_id = ?", userDeviceID)

}
}
return func(db *gorm.DB) *gorm.DB { return db }
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.