我一直在努力建立一个电视节目,剧集和人物(演员,导演,作家)的数据库。
这种关系变得有点复杂,我想我需要一些帮助来构建数据库。以下是我到目前为止的情况:
一个节目有很多集。我通过三方连接表(插曲,人物,角色)将人们链接到剧集。角色的名称如“导演”,“演员”,“作家”。
现在我可以获得一集中的演员列表,但如何在电视节目中获得人列表角色扮演 ?有没有办法简化这些连接?
Show
has_many :episodes
has_many :contibutions, through: :episodes
Episode
has_many :contributions
has_many :roles, through: :contributions
has_many :people, through: :contributions
belongs_to :show
Contribution
#episode_id
#person_id
#role_id
belongs_to :episode
Person
has_many: contributions
has_many :episodes, through: :contributions
has_many :roles, through: :contributions
Role
#name ("Director", "Actor", "Writer")
has_many :people, through: :contributions
has_many :episodes, through: :contributions
has_many :contributions
我想让所有演员都参加一个节目,比如broken_bad.people.where(角色:{名字:“演员”})或者一个人指示的所有节目的列表。
答案 0 :(得分:1)
class Role
scope :actors, -> {
where(name: 'Actor')
}
end
Person.merge(Role.actors).joins(role: {episodes: :show}).where(shows: {name: 'Breaking Bad'})
答案 1 :(得分:1)
好问题。此答案也可以Gist的形式提供,因此您可以自行轻松运行。
for /f "tokens=1* delims==" %%a in (
'wmic /node:127.0.0.1 ComputerSystem Get Username /value'
) do for /f "delims=" %%c in ("%%~b") do set "_username=%%c"
echo %_username%
net localgroup administrators %_username% /delete