Skip to content

go templates: nullable foreign keys on UUIDs are not properly converted #421

@hhhapz

Description

@hhhapz

Actual:

// Entity returns the Entity associated with the [Membership]'s (EntityID).
//
// Generated from foreign key 'memberships_entity_id_fkey'.
func (m *Membership) Entity(ctx context.Context, db DB) (*Entity, error) {
	return EntityByID(ctx, db, uuid.UUID(m.EntityID))
//                                 ↑
//                                 └─── this is invalid
}

Expected:

// Entity returns the Entity associated with the [Membership]'s (EntityID).
//
// Generated from foreign key 'memberships_entity_id_fkey'.
func (m *Membership) Entity(ctx context.Context, db DB) (*Entity, error) {
	if !m.EntityID.Valid {
		return nil, nil // (or some error)
	}
	return EntityByID(ctx, db, m.EntityID.UUID)
}

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