Fakultas Ilmu Komputer UI

Commit 462ccd21 authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

Create Query Builder module for Post Schema

parent 752a9d80
defmodule Diskuy.ForumPostPage do
@moduledoc """
The Query Builder For Paging Thread Schema.
import Ecto.Query, warn: false
alias Diskuy.Account.User
alias Diskuy.Forum.Thread
alias Diskuy.Forum.Post
def page_per_thread(thread_id) do
|> where([p], p.thread_id == ^thread_id)
|> order_by([p], asc: p.inserted_at)
defp query_start do
|> join(:inner, [p], u in User, as: :users, on: p.user_id == u.id)
|> join(:left, [p], tr in Thread, as: :threads, on: p.thread_id == tr.id)
|> select([p, u], %{id: p.id, message: p.message,
points: p.points,
user_id: p.user_id, thread_id: p.thread_id,
parent_id: p.parent_id,
username: u.username, inserted_at: p.inserted_at,
updated_at: p.updated_at
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment