Skip to content

"Filter By" using Field Alias #168

@sulthonzh

Description

@sulthonzh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions