问题描述
当表中存在关联时,我想向模型添加一个标志。在我的用户模型中,我具有以下字段:field :is_employed,:boolean,virtual: true,default: false
我可以结合使用select_merge
和exists
吗?
User
|> ...
|> select_merge([u],%{is_employed: Repo.exists(from t in Task,where: u.id == t.user_id and t.status == "in_progress")})
|> Repo.all()
解决方法
std::tuple<char,long long,double,long double,float> some_values(33,2,3.4,5.6,7.8);
constexpr size_t length_of_first_part = 2;
split_apply<length_of_first_part>(
[](auto&&... current_val) {
((std::cout << "(Should be first part) " << current_val << "\n"),...);
},[](auto&&... current_val) {
((std::cout << "(Should be second part) " << current_val << "\n"),...);
},some_values);
解决此问题的一种方法是拥有数据联接,您可以直接使用它们进一步查询适当的数据。