-
Notifications
You must be signed in to change notification settings - Fork 72
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
Allow explicit FK fields for inverse relations #237
Comments
You can query FK values with: post.Value(Schema.Post.AuthorFK.String()) But is a bit ugly indeed. There is no easy way to access them because when you use an ORM, you usually want to hide that complexity. That's a design decision I don't agree with, tho. |
I'd rather consider this as extra complexity: post.Value(Schema.Post.AuthorFK.String()) And yes, it's ugly. Option to allow using struct fields for FKs would be awesome (and backward compatible). What about loading relations on existing (already fetched) object? I mean something like p := PostStore(db).FindOne(NewPostQuery().FindByID(id)
// something happen and suddenly you also need to load author
p.LoadAuthor() // <- how to do this without using p.Value(Schema.Post.AuthorFK.String())? |
You can use the same trick: authorId, err := post.Value(Schema.Post.AuthorFK.String())
// TODO: check err
authorStore.FindOne(NewAuthorQuery().FindByID(int64(authorId)))
|
Anyway, looks like you have no idea either... |
Oh, sorry, I totally missed the comment. I'm afraid it is not possible to do that without asking the schema for stuff. This is by design, changing this behaviour would require a major refactor of how virtual columns and FKs work. |
Status updateThis is indeed a desired feature. However, adding an extra field named This is certainly on my TODO list. |
@roobre sometimes you can assign FK without fetching full related records, in such cases read-only API may lead to redundant work. |
Maybe we can cover that on #219. |
From readme:
AFAICT there is no way to get fk value without querying relation. And when I include foreign key to struct, kallax generates invalid code.
Kallax generates duplicate switch statement cases for
"author_id"
field infunc (r *Post) ColumnAddress
andfunc (r *Post) Value
methods.UPDATE
And by the way, how to load "inverse" relations for object without re-querying everything using
With<Relation>
methods ? This "virtual columns" seem to just add more complexity and inconveniences without providing reasonable value.The text was updated successfully, but these errors were encountered: