township-agency / ex_teal

MIT License
1 stars 0 forks source link

feat: Related Search, Sort and deep ManyToMany customization" #209

Closed staylorwr closed 1 year ago

staylorwr commented 1 year ago

mad

ManyToMany.make(:mentors, Mentor)
|> ManyToMany.with_index_fields([
  Text.make(:last_name),
  Text.make(:first_name),
  Select.make(:pronouns, "Preferred Pronouns")
  |> Select.options(~w(he/him she/her they/them)),
  Text.make(:login_code),
  date_field(:background_check_on),
  date_field(:consent_form_received_on),
  Number.make(:sessions_completed)
])
|> ManyToMany.with_index_query(fn query, _assoc, program_id ->
  from(
    m in query,
    left_join: s in Voyager.Edu.Session, on: s.mentee_id == m.id and s.program_id == ^program_id and not is_nil(s.completed_on),
    select_merge: %{sessions_completed: count(s.id)},
    group_by: m.id
  )
end),
Screenshot 2023-07-19 at 9 21 38 AM