<p>I realise this isn't really a Q&A sub, but I asked on Stack Overflow and IRC and didn't get any responses, so I figured this couldn't hurt.</p>
<p>I want a database that looks like this:</p>
<pre><code>groups table
id | name
----|---------
1 | "Family"
2 | "Friends"
shows table
id | name
----|---------
1 | "Seinfeld"
2 | "The X-Files"
groups_shows_link
group_id | show_id | rewatch
---------|---------|---------
1 | 1 | 1508764915
2 | 1 | 1508522911
</code></pre>
<p>That is, I want to put an extra field <code>rewatch</code> on the join table, and then be able to ask Gorm for all of group 1's shows, <em>or</em> all of group 1's shows <code>where rewatch > ?</code>.</p>
<p>I'm not sure what to call this to search for it, nor can I find information about such a thing in Gorm's documentation. What should I do in this situation?</p>
<p>Right now my <code>Group</code> struct has <code>Shows []Show</code>, and that creates the join table just fine, but I can't see a way to add a column to it. It occurred to me to create an entirely new <code>GroupShowsLink</code> struct with a <code>rewatch int</code> field, and say that each group has 1 of those, and each of of those has 1 show, but that seems pretty hacky and like it'd be messy to search through?</p>
<hr/>**评论:**<br/><br/>gopher2018: <pre><p>I don't think Gorm supports adding columns to join tables.</p>
<p>I recomment you to create a dedicated struct to the join table. Then you have the flexibility to add column and write any SQL you want.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传