Skip to content

Instantly share code, notes, and snippets.

@andrelip
Last active September 3, 2017 16:52
Show Gist options
  • Select an option

  • Save andrelip/f8cc72808d7ad322abdf0e684920807e to your computer and use it in GitHub Desktop.

Select an option

Save andrelip/f8cc72808d7ad322abdf0e684920807e to your computer and use it in GitHub Desktop.
------------
CODE
------------
books_scope = from(b in Book,
where: b.layout == "dynamic")
from(n in ViewedBook,
join: b in subquery(books_scope),
on: b.id == n.book_id,
where: n.book_id == b.id,
where: n.profile_id == ^reader_id,
order_by: [desc: :updated_at],
select: n)
# it works with ^"dynamic"
------------
ERROR
------------
Request: POST /graphql
** (exit) an exception was raised:
** (Ecto.QueryError) deps/ecto/lib/ecto/query/planner.ex:18: field `Arvore.ReaderAccount.ViewedBook.layout` in `join` does not exist in the schema in query:
from v in Arvore.ReaderAccount.ViewedBook,
join: b in Arvore.BookCollection.Book,
on: b.layout == "dynamic" and b.id == v.book_id,
where: v.book_id == b.id,
where: v.profile_id == ^190,
order_by: [desc: v.updated_at],
select: v
-----------
details:
-----------
schema "books" do
field :name, :string
field :slug, :string
field :author, :string
field :degree, :string
field :description, :string
field :layout, :string
field :image, :string
field :v2ready, :boolean
field :viewed_count, :integer
field :disabled, :boolean
field :price, :decimal
belongs_to :bisac, Bisac
end
schema "viewed_books" do
belongs_to :reader, Reader, foreign_key: :profile_id
belongs_to :book, Book
field :percentage, :decimal;
timestamps([{:inserted_at,:created_at}])
end
#Ecto.Query<from b in Arvore.BookCollection.Book, where: b.layout == "dynamic">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment