ganncamp
(G Ann Campbell)
2022 年 4 月 19 日午後 6:02
1
I’ve noticed that if I select an FK ID in a table, I get a beautifully presented, linked name. Whereas if I select a PK ID in a table, I just get a number.
For example, when I select the (PK) id field from Posts:
Versus when I select the (FK) topic_id field from Posts:
I’ve been wondering if there’s some sleight-of-hand I can do to get this lovely linking behavior from PKs. Or do I always need to throw in an extra table & select from it when I want linking?
「いいね!」 2
You can alias that particular id
to post_id
and it will work its magic. Eg.
SELECT id AS post_id
FROM posts
ORDER BY created_at DESC
「いいね!」 9
tshenry
(Taylor)
2022 年 4 月 20 日午前 2:52
3
There are actually quite a few other little tricks to beautifying your results in the Discourse UI.
This old file shows some examples:
SELECT
(SELECT id FROM badges LIMIT 1) as badge_id,
(SELECT id FROM categories LIMIT 1) as category_id,
(SELECT id FROM groups LIMIT 1) as group_id,
'<h2 class="fa fa-google"> hello</h2>' as html$html,
(SELECT id FROM posts LIMIT 1) as post_id,
'hello' as text$text,
(SELECT id FROM topics LIMIT 1) as topic_id,
(SELECT id FROM users LIMIT 1) as user_id,
TIMESTAMP 'yesterday' as reltime$time,
1 as end
I’ll integrate this into the main Data Explorer topic at some point when I have a spare moment.
「いいね!」 10
I also like the admin url one for making interactive user lists:
SELECT
'/admin/users/' || users.id || '/' || users.username_lower
AS admin_page_url
FROM users
「いいね!」 7
system
(system)
クローズされました:
2022 年 6 月 17 日午後 5:28
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.