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

Resolve target Model primary key type for BelongsTo|HasManyKey|HasOnKey #118

Merged
merged 4 commits into from
Jan 19, 2017

Conversation

aslakknutsen
Copy link
Contributor

Instead of hard-coding the Type of a BelongsTo|HasManyKey|HasOneKey relationship
to be in, resolve the target model in the relationship and use its PrimaryKey as
xID type in source struct.

Note: Currently this will panic if multiple PrimaryKeys are defined.

fixes #115

Instead of hard-coding the Type of a BelongsTo|HasManyKey|HasOneKey relationship
to be in, resolve the target model in the relationship and use its PrimaryKey as
xID type in source struct.

Note: Currently this will panic if multiple PrimaryKeys are defined.

fixes goadesign#115
@aslakknutsen
Copy link
Contributor Author

Just noticed, while the correct Go Type is now working, the SQLTag type is not. And SQLTag can contain anything, so I guess we need to parse it and look for 'only parts of it' that would be relevant to a foreign key. (e.g. type is, but default is not)

Maybe we need to open up this in the DSL?

BelongsTo("Identity", func() {
    SQLTag("type:uuid")
})

@aslakknutsen
Copy link
Contributor Author

Also, BelongsTo filters currently not working. Hardcoded to int

return "int"
}
modelName := strings.Replace(f.FieldName, "ID", "", -1)
model := f.Parent.BelongsTo[modelName]

This comment was marked as off-topic.

@bketelsen
Copy link
Member

some questions in the code, generally I don't see a problem. Have you generated an app with this yet?

@aslakknutsen
Copy link
Contributor Author

Yes I have. This was what I had to do to get UUID working. :) It's currently semi depending on a change in Goa as well to reintroduce satori/go.uuid that has the Scan/Value interface implemented.

@aslakknutsen
Copy link
Contributor Author

The current impl shortcuts a little and makes it "BelongsTo("Model", "SQLTag")' as oppose to passing in a dsl func to BelongsTo that supports SQLTag. What's your opinion here?

@secretfader
Copy link

I'm currently blocked on Gorma UUID support. Any idea when this PR might be merged?

@bketelsen bketelsen merged commit 8ddc765 into goadesign:master Jan 19, 2017
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

Successfully merging this pull request may close these issues.

BelongsTo relationship generates wrong xID type when using UUID
3 participants