Why is Enum.group_by returning this?

I have a table where the column has assign_id and assign_type. First I’m loading all the data where assign_id is 1 and then I’m doing a group_by for how many assign_type is associated with assign_id

So first I loaded all the data by this

query = from(a in Amenity,
where: a.assign == ^assign_id,
)

query
|> Repo.all()
|> Enum.group_by(fn(item) → item.assign_type end)

But it’s giving me a result like this

%{
nil: [
      %Amenity{
            assign_id: 1,
            assign_type: "user"
        }
     ]
}

I think you’re leaving out some information. The code you’ve written should show %Amenity{} structs, but you’re showing simple maps. Can you show the actual code you’re running and the actual results?

Sorry, I missed that by mistake.

But the result I want something like this

[
   %Amenity{
            assign_id: 1,
            assign_type: "user"
        },
   %Amenity{
            assign_id: 1,
            assign_type: "user 2"
        }
]

for the next step, I wanted to check how many assign_type is defined for the same assign_id.