如何对“特色”的概念进行建模? (即,当某位艺术家出现在歌曲中时)
有时,一首歌会有不止一位艺术家参与。例如,Jay-z 的新歌“A Star is Born”以艺术家 Cole 为主角,因此在目录中将被列为“Jay-z (featuring Cole) - A Star is Born”。我的问题是如何在我的数据库中对此进行建模。
现在非常简单:每首歌曲belongs_to :artist
并且每个艺术家has_many :songs
。我想改变这一点,以便歌曲有许多艺术家,其中一位艺术家被指定为“主要”——即,如果 A、B 和 C 都与给定歌曲相关联,并且 A 是主要的,则该歌曲的艺术家将是显示为“A(包含 B 和 C)”。
这是我的想法:
歌曲:
has_many :artists, :through => :performances
艺术家:
has_many :songs, :through => :performances
其中 performance
模型将有一个 primary?
字段,指定给定的表演是否是“主要”表演歌曲,这意味着与该表演相关的艺术家是该歌曲的主要艺术家。
这种方法有意义吗?
Sometimes more than one artist will be on a song. For example, Jay-z's new song "A Star is Born" features the artist Cole, and thus would be listed as "Jay-z (featuring Cole) - A Star is Born" in a catalog. My question is how to model this in my database.
Right now it's pretty simple: every song belongs_to :artist
and every artist has_many :songs
. I want to change this so that songs have many artists, with one artist specified as "primary" -- i.e., if A, B, and C are all associated with a given song and A is primary, the artist of that song will be displayed as "A (featuring B and C)".
Here's what I'm thinking:
Song:
has_many :artists, :through => :performances
Artist:
has_many :songs, :through => :performances
where the performance
model would have a single field for primary?
, designating whether a given performance was the "primary" performance on the song, meaning that the artist associated with that performance is the primary artist on the song.
Does this approach make sense?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。你成功了。
Yes. You nailed it.
看起来您正在使用表演作为连接表,并添加了将歌曲与艺术家链接起来的信息。但这效果还不够好。歌曲可以有多次表演,每场表演可以有多个表演者。
我将重组数据库以使用以下结构。不幸的是,将歌曲添加到数据库需要更多的工作,但允许翻唱、歌曲的多个版本和二重唱。
歌曲(属性:标题)
表演(外键:Song_id,属性:日期、年份、长度、流派、专辑,)
表演者(外键:Performance_id,Artist_id,属性:角色)
艺术家(属性:姓名、出生日期等(其他个人信息))
如果您想强制执行 1 个主要艺术家/表演,则可以在表演者中进行验证。
It looks like you're using performances as an join table with added information to link songs to artists. But this does not work well enough. Songs can have many performances, and each performance can have multiple performers.
I would restructure the database to use a the following structure. Unfortunately it would require a little more work to add a Song to the database, but allows for covers, multiple versions of the song, and duets.
Song (Attributes: Title)
Performance (Foreign Key: Song_id, Attributes: Date, Year, Length, Genre, Album, )
Performers (Foreign keys: Performance_id, Artist_id, Attributes: Role)
Artist (Attributes: Name, Date of Birth, etc. (other Personal inforamtion))
If you wanted to enforce 1 primary artist/performance it would be done as validation in Performers.