1

你好!我只想获取下载链接的重要信息(完整流程)。

我的域设计如下:

Serie { hasMany[Season] }
Season { hasMany[Episode] and belongsTo[Serie] }
Episode { hasMany[DownloadInfo] and belongsTo[Season] }
DownloadInfo { link nullable:true //among other data }

我的数据库中有大约这个数量的记录:

serie:4500
season:500
episode:6500
download_info:10000

我们可以看到有很多系列没有其他信息。

我怎样才能只在所有这些都完成的地方获得那些系列>季>集>下载信息数据?

例如,拥有:

Serie "A"
  Season "sA1"
Serie "B"
  Season "sB1"
    Episode "eB1"
      Link "b1.1"
      Link "b1.2"
    Episode "eB2"
    Episode "eB3"
      Link "b3.1"
Serie "C"
  Season "sC1"
    Episode "eC1"
Serie "D"
Serie "E"
  Season "sE1"
    Episode "eE1"
      Link "e1.1"
  Season "sE2"
    Episode "eE2"
      Link "e2.1"

我想得到这个:

def model = [series:[
  name:'B',
  seasons:[
    name:'sB1',
    episodes:[
      name:'eB1',
      links:['b1.1','b1.2']
    ],[
      name:'eB3',
      links:['b3.1']
    ]
  ]
],[
  name:'E'
  seasons:[
    name:'sE1',
    episodes:[
      name:'eE1',
      links:['e1.1']
    ]
  ],[
    name:'sE2'
    episodes:[
      name:'eE2',
      links:['e2.1']
    ]
  ]
]

丢弃所有没有链接的系列、季节剧集和下载信息。

顺便说一句,我只需要链接属性不为空的 DownloadInfo。我开始:

DownloadInfo.where { link!= null }.list().each {
  // ...
}

但我想不出一种优雅的方式来完成所有流程。有什么线索吗?

提前致谢!

更新

这将是 Groovy 的等价于以下 SQL,按每个实体的名称分组:

select * from serie s
inner join season ss on s.id = ss.serie_id
inner join episode e on ss.id = e.season_id
inner join download_info di on e.id = di.episode_id
where di.link is not null
4

0 回答 0