如何使用 HQL 过滤外键引用模型拥有的字段?
How to filter fields owned by a foreign-key-referred-model with HQL?
例如模型Comment
有字段:
content
account
(参考型号Account
)
article
(参考型号Article
)
现在如果我想在查询时过滤整个article
字段,我可以为class定义一个没有content
的构造方法 Comment
赞:
public Comment(String content, Account account) {
this.content = content;
this.account = account;
}
并定义查询:
@Query("SELECT NEW Comment(content, account) FROM Comment WHERE channel_id = ?1")
List<Comment> findCommentsByChannel_Id(Long channel_id);
但是现在我也想过滤字段account
的字段password
,请问如何实现?
只需使用您要保留的属性创建 Projections。
例如模型Comment
有字段:
content
account
(参考型号Account
)article
(参考型号Article
)
现在如果我想在查询时过滤整个article
字段,我可以为class定义一个没有content
的构造方法 Comment
赞:
public Comment(String content, Account account) {
this.content = content;
this.account = account;
}
并定义查询:
@Query("SELECT NEW Comment(content, account) FROM Comment WHERE channel_id = ?1")
List<Comment> findCommentsByChannel_Id(Long channel_id);
但是现在我也想过滤字段account
的字段password
,请问如何实现?
只需使用您要保留的属性创建 Projections。