sqlboiler: ForeignFN conflicts with ColumnName

I am seeing a conflict in all my foreign keys for these two function. I can see that if you have user_id as a foreign key, you would get UserId as field and User() as foreign function?

ForeignFn: https://github.com/volatiletech/sqlboiler/blob/7d3d954a4be10dc06b9464fb3e6d74836274c467/boilingcore/text_helpers.go#L40

ColumnName: https://github.com/volatiletech/sqlboiler/blob/4dea9a5f77e3ec6090ad455df3d408e47e077700/boilingcore/aliases.go#L78

I found the following logic help:

       if foreignFn == fkColumnName {
		if strings.HasPrefix(foreignFn, foreignTableName) {
			foreignFn = foreignTableName
		} else {
			foreignFn += foreignTableName
		}
	}

So if you have CreatedBy to the User table, it would generate foreignn fn CreatedByUser() and if you have UserIdentifier on the User table, foreign fn would be User()

I know there are aliases in the config file, but when every table have a User field called created_by, it seems to be troublesome to have set same alias across 100 tables. If aliases work from the destination table or there is a global list of aliases that would be great as well.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 15 (8 by maintainers)

Most upvoted comments