Serializing related items (for HTMx view) #1628
Unanswered
garvanwalshe
asked this question in
Q&A
Replies: 1 comment
-
|
You could have your Model for GeographicalRegion be something like GeographicalRegion {
name: String,
containing_region: Option<GeographicalRegion>,
}and serialize it like that i believe. Then you fetch the region and containing with .find_related(). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm testing out loco, which I'm really impressed with, but I'm having one problem here that probably has a very obvious solution even if it hasn't occurred to me yet.
I have a table of geographical reagions in which one column is a self-referencing key, so that it can record which regions are in other regions (eg: Dublin is in Leinster which is in Ireland...) but when it's serialised to a view it only returns the id of the containing region, whereas I want to display its name in the views.
The generators have correctly produced the appropriate self-reference in sea-orm.
Is there currently a way to have the serialiser follow relations (up to a certain depth perhaps), rather than stopping at the ids? I know there are other places one could follow them - in the controller, or even in the view, but this seems to me to be the cleanest way of at least reading from linked models.
Or would I have to rewrite the serializers/deseriallizers to do that, and if so does the community have views on whether that's a good idea?
Beta Was this translation helpful? Give feedback.
All reactions