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

"Filter By" using Field Alias #168

Open
sulthonzh opened this issue Jul 16, 2018 · 0 comments
Open

"Filter By" using Field Alias #168

sulthonzh opened this issue Jul 16, 2018 · 0 comments

Comments

@sulthonzh
Copy link
Contributor

sulthonzh commented Jul 16, 2018

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 }
}
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