How do I use relationship_display_fields
Could you please explain how to use
relationship_display_fields
? I couldn't figure it out from the docs or the tweet.
Alternatively, is there a way to link the referencing id to the object in the admin panel? eg. if you have a user_id
, clicking the user_id
takes you to the page for that user29 Replies
Currently there is not a way to do that AFAIK. PRs welcome! Although its looking like we're going to reimagine that project 🙂
relationship_display_fields
dictates how the value appears in the data tables
i.e relationship_display_fields [:id, :email]
would show something like 1 - [email protected]
i still don't follow - does it show how it appears in other data tables?
what is the relationship part referring to
Ah, yeah so its referring to other things that are related to it
when showing in their data tables, it will show those fields
so if I have
user
and note
and a note
belongs to a user
adding relationship_display_fields [:email]
would make it automatically show the user's email when in note data table?yes, it should at least 🙂
it doesn't seem to work 😦
😢
do i need to do anything on
note
as well?Do you see anything for the user at all in the note table?
Or what are you seeing?
just the
user_id
🤔 🤔
oh, okay
try setting the table columns explicitly
this is in
note
?So we do that logic when you ask for us to show a relationship in the table columns
Yeah
What its showing now is the attribute of
user_id
So asking it to display the :user
specifically will trigger that logicah that works
I wonder if that is clickable
nope
haha
damn 🙂
Honestly the admin UI is very useful but its still super raw
oh but I didn't realize when I click into the table row it shows the relationships right there
which is pretty much what i needed
those might actually be clickable
clicking show on there just refreshes the page
🤔 well, thats a bug
is there an easy way to have the
table_columns
be all the existing columns + user
i don't want to enumerate my columns every timeDepends on what you'd call easy 🙂
but the answer is probably no
haha ok
I could walk you through how we might add it though
i guess i can write my own method using the introspection
Yeah, the main problem is that within the DSL module there you can't really do introspection at that point
what you'd have to do is write an extension
So then you could do
haha ok i'm going to have to analyze this closely
Yeah its a lot to grok 😆 but once you know how to write extensions you can do pretty much anything
Transformers, which are provided by extensions, can make arbitrary transformations to resources
So you can use that pattern to do all kinds of stuff, like modify any option/alter the attributes/relationships or whatever you want really.