Skip to content

Instantly share code, notes, and snippets.

@mazz
Created November 2, 2019 20:01
Show Gist options
  • Save mazz/5d7f957c1eae8a7705ff3d787dd3856a to your computer and use it in GitHub Desktop.
Save mazz/5d7f957c1eae8a7705ff3d787dd3856a to your computer and use it in GitHub Desktop.
field `taskcategories` in `select` is a virtual field in schema Db.Schema.Task in query:
query =
from(task in Task,
join: org in Org,
join: rubric in Rubric,
join: coursecode in CourseCode,
join: task_category in TaskCategory,
where: org.uuid == ^org_uuid,
where: org.id == task.org_id,
where: rubric.id == task.rubric_id,
where: coursecode.id == task.coursecode_id,
where: task_category.task_id == task.id,
preload: [taskcategories: :taskitems],
select: %{
title: task.task_title,
uuid: task.uuid,
org_uuid: org.uuid,
archived: task.archived,
course_task_type: task.course_task_type,
task_id: task.id,
rubric: rubric,
coursecode: coursecode,
task_category: task.taskcategories,
inserted_at: task.inserted_at,
updated_at: task.updated_at,
hash_id: task.hash_id
}
)
@mazz
Copy link
Author

mazz commented Nov 2, 2019

fixed:

  def tasks_by_org_uuid(orguuid, offset, limit) do
    {:ok, org_uuid} = Ecto.UUID.dump(orguuid)

    query =
      from(task in Task,
      join: org in Org,
      join: rubric in Rubric,
      join: coursecode in CourseCode,
      where: org.uuid == ^org_uuid,
        where: org.id == task.org_id,
        where: rubric.id == task.rubric_id,
        where: coursecode.id == task.coursecode_id,
        preload: [:taskcategories, taskcategories: :taskitems],
        select: %{task: task, coursecode: coursecode,  rubric: rubric, org: org}
      )

    query
    |> Repo.paginate(page: offset, page_size: limit)
  end

@tblevins-pv
Copy link

What was the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment