Elixir 任何因为你有很多联系

Elixir 任何因为你有很多联系,elixir,phoenix-framework,Elixir,Phoenix Framework,我有一个用户模型,有许多组 web/models/user.ex defmodule MyApp.User do 使用MyApp.Web,:model 使用Arc.exto.Model 模式“用户”做什么 字段:名字,:字符串 字段:姓氏,:字符串 有很多:群组,MyApp.Group [...] 在user#show模板中,我希望呈现现有的组(如果有)。如果没有,我什么也不想渲染 web/templates/user/show.html.eex […] 组 您可以检查组集合是否不是空列表,

我有一个
用户
模型,
有许多

web/models/user.ex

defmodule MyApp.User do
使用MyApp.Web,:model
使用Arc.exto.Model
模式“用户”做什么
字段:名字,:字符串
字段:姓氏,:字符串
有很多:群组,MyApp.Group
[...]
user#show
模板中,我希望呈现现有的
(如果有)。如果没有,我什么也不想渲染

web/templates/user/show.html.eex

[…]
组

    您可以检查组集合是否不是空列表,或者使用
    Enum.empty?/1
    函数:

    if @user.groups != [] do
      # ...
    end
    
    if not Enum.empty?(@user.groups) do
      # ...
    end